Skip to content

Commit c6cbb2f

Browse files
MCP Funcional
0 parents  commit c6cbb2f

21 files changed

+10444
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.wrangler
3+
.env

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:18-alpine
2+
3+
WORKDIR /app
4+
5+
# Copiar arquivos do projeto
6+
COPY package*.json ./
7+
COPY tsconfig.json ./
8+
COPY wrangler.toml ./
9+
COPY src ./src
10+
11+
# Instalar dependências
12+
RUN npm install
13+
14+
# Compilar TypeScript
15+
RUN npm run build
16+
17+
# Expor a porta
18+
EXPOSE 8787
19+
20+
# Comando para iniciar o servidor
21+
CMD ["npm", "run", "start"]

README.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Chatwoot MCP Server
2+
3+
Este é um servidor MCP (Model Context Protocol) que fornece ferramentas para interagir com a API do Chatwoot.
4+
5+
## Ferramentas Disponíveis
6+
7+
1. `chatwoot_setup`: Configura a conexão com o Chatwoot
8+
- Parâmetros:
9+
- `baseUrl`: URL base da sua instalação do Chatwoot
10+
- `apiToken`: Token de API do Chatwoot
11+
12+
2. `chatwoot_list_inboxes`: Lista todas as caixas de entrada
13+
- Sem parâmetros
14+
15+
3. `chatwoot_list_conversations`: Lista conversas
16+
- Parâmetros opcionais:
17+
- `inbox_id`: ID da caixa de entrada
18+
- `status`: Status das conversas ("open", "resolved", "pending")
19+
20+
4. `chatwoot_send_message`: Envia uma mensagem
21+
- Parâmetros:
22+
- `conversation_id`: ID da conversa
23+
- `message`: Conteúdo da mensagem
24+
- `message_type`: Tipo da mensagem ("incoming" ou "outgoing")
25+
26+
5. `chatwoot_update_conversation`: Atualiza o status de uma conversa
27+
- Parâmetros:
28+
- `conversation_id`: ID da conversa
29+
- `status`: Novo status ("open", "resolved", "pending")
30+
31+
## Instalação
32+
33+
### Desenvolvimento Local
34+
35+
1. Clone o repositório
36+
2. Instale as dependências:
37+
```bash
38+
npm install
39+
```
40+
3. Inicie o servidor de desenvolvimento:
41+
```bash
42+
npm run start
43+
```
44+
45+
### Deploy com Docker
46+
47+
1. Clone o repositório
48+
2. Construa e inicie os containers:
49+
```bash
50+
docker-compose up -d
51+
```
52+
53+
O servidor estará disponível em `http://localhost:8787/sse`.
54+
55+
## Uso com Clientes MCP
56+
57+
1. Conecte-se ao servidor usando a URL: `http://seu-servidor:8787/sse`
58+
2. Configure o cliente usando a ferramenta `chatwoot_setup`
59+
3. Comece a usar as outras ferramentas disponíveis
60+
61+
## Exemplo de Uso
62+
63+
```typescript
64+
// Configurar o cliente
65+
await mcp.invoke("chatwoot_setup", {
66+
baseUrl: "https://seu-chatwoot.com",
67+
apiToken: "seu-token-api"
68+
});
69+
70+
// Listar caixas de entrada
71+
const inboxes = await mcp.invoke("chatwoot_list_inboxes");
72+
73+
// Listar conversas abertas
74+
const conversations = await mcp.invoke("chatwoot_list_conversations", {
75+
status: "open"
76+
});
77+
78+
// Enviar mensagem
79+
await mcp.invoke("chatwoot_send_message", {
80+
conversation_id: 123,
81+
message: "Olá! Como posso ajudar?",
82+
message_type: "outgoing"
83+
});
84+
```
85+
86+
## Connect the MCP inspector to your server
87+
88+
To explore your new MCP api, you can use the [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector).
89+
90+
- Start it with `npx @modelcontextprotocol/inspector`
91+
- [Within the inspector](http://localhost:5173), switch the Transport Type to `SSE` and enter `http://localhost:8787/sse` as the URL of the MCP server to connect to, and click "Connect"
92+
- You will navigate to a (mock) user/password login screen. Input any email and pass to login.
93+
- You should be redirected back to the MCP Inspector and you can now list and call any defined tools!
94+
95+
<div align="center">
96+
<img src="img/mcp-inspector-sse-config.png" alt="MCP Inspector with the above config" width="600"/>
97+
</div>
98+
99+
<div align="center">
100+
<img src="img/mcp-inspector-successful-tool-call.png" alt="MCP Inspector with after a tool call" width="600"/>
101+
</div>
102+
103+
## Connect Claude Desktop to your local MCP server
104+
105+
The MCP inspector is great, but we really want to connect this to Claude! Follow [Anthropic's Quickstart](https://modelcontextprotocol.io/quickstart/user) and within Claude Desktop go to Settings > Developer > Edit Config to find your configuration file.
106+
107+
Open the file in your text editor and replace it with this configuration:
108+
109+
```json
110+
{
111+
"mcpServers": {
112+
"math": {
113+
"command": "npx",
114+
"args": [
115+
"mcp-remote",
116+
"http://localhost:8787/sse"
117+
]
118+
}
119+
}
120+
}
121+
```
122+
123+
This will run a local proxy and let Claude talk to your MCP server over HTTP
124+
125+
When you open Claude a browser window should open and allow you to login. You should see the tools available in the bottom right. Given the right prompt Claude should ask to call the tool.
126+
127+
<div align="center">
128+
<img src="img/available-tools.png" alt="Clicking on the hammer icon shows a list of available tools" width="600"/>
129+
</div>
130+
131+
<div align="center">
132+
<img src="img/claude-does-math-the-fancy-way.png" alt="Claude answers the prompt 'I seem to have lost my calculator and have run out of fingers. Could you use the math tool to add 23 and 19?' by invoking the MCP add tool" width="600"/>
133+
</div>
134+
135+
## Deploy to Cloudflare
136+
137+
1. `npx wrangler kv namespace create OAUTH_KV`
138+
2. Follow the guidance to add the kv namespace ID to `wrangler.jsonc`
139+
3. `npm run deploy`
140+
141+
## Call your newly deployed remote MCP server from a remote MCP client
142+
143+
Just like you did above in "Develop locally", run the MCP inspector:
144+
145+
`npx @modelcontextprotocol/inspector@latest`
146+
147+
Then enter the `workers.dev` URL (ex: `worker-name.account-name.workers.dev/sse`) of your Worker in the inspector as the URL of the MCP server to connect to, and click "Connect".
148+
149+
You've now connected to your MCP server from a remote MCP client.
150+
151+
## Connect Claude Desktop to your remote MCP server
152+
153+
Update the Claude configuration file to point to your `workers.dev` URL (ex: `worker-name.account-name.workers.dev/sse`) and restart Claude
154+
155+
```json
156+
{
157+
"mcpServers": {
158+
"math": {
159+
"command": "npx",
160+
"args": [
161+
"mcp-remote",
162+
"https://worker-name.account-name.workers.dev/sse"
163+
]
164+
}
165+
}
166+
}
167+
```
168+
169+
## Debugging
170+
171+
Should anything go wrong it can be helpful to restart Claude, or to try connecting directly to your
172+
MCP server on the command line with the following command.
173+
174+
```bash
175+
npx mcp-remote http://localhost:8787/sse
176+
```
177+
178+
In some rare cases it may help to clear the files added to `~/.mcp-auth`
179+
180+
```bash
181+
rm -rf ~/.mcp-auth
182+
```

biome.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.6.2/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"files": {
7+
"ignore": ["worker-configuration.d.ts"]
8+
},
9+
"vcs": {
10+
"enabled": true,
11+
"clientKind": "git",
12+
"useIgnoreFile": true
13+
},
14+
"linter": {
15+
"enabled": true,
16+
"rules": {
17+
"recommended": true,
18+
"suspicious": {
19+
"noExplicitAny": "off",
20+
"noDebugger": "off",
21+
"noConsoleLog": "off",
22+
"noConfusingVoidType": "off"
23+
},
24+
"style": {
25+
"noNonNullAssertion": "off"
26+
}
27+
}
28+
},
29+
"formatter": {
30+
"enabled": true,
31+
"indentWidth": 4,
32+
"lineWidth": 100
33+
}
34+
}

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
3+
services:
4+
chatwoot-mcp:
5+
build: .
6+
ports:
7+
- "8787:8787"
8+
restart: unless-stopped
9+
environment:
10+
- NODE_ENV=production

img/available-tools.png

91.5 KB
Loading
466 KB
Loading

img/mcp-inspector-oauth-success.png

403 KB
Loading

img/mcp-inspector-sse-config.png

333 KB
Loading

0 commit comments

Comments
 (0)