@elizaos/plugin-mcp 2.0.0-alpha.7 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +269 -0
  2. package/dist/cjs/index.cjs +822 -358
  3. package/dist/cjs/index.js.map +19 -18
  4. package/dist/node/actions/mcp.d.ts +6 -0
  5. package/dist/node/actions/mcp.d.ts.map +1 -0
  6. package/dist/node/index.d.ts +1 -0
  7. package/dist/node/index.d.ts.map +1 -1
  8. package/dist/node/index.js +818 -362
  9. package/dist/node/index.js.map +19 -18
  10. package/dist/node/mcp-marketplace.d.ts +69 -0
  11. package/dist/node/mcp-marketplace.d.ts.map +1 -0
  12. package/dist/node/prompts.d.ts +23 -0
  13. package/dist/node/prompts.d.ts.map +1 -0
  14. package/dist/node/provider.d.ts.map +1 -1
  15. package/dist/node/routes-mcp.d.ts +48 -0
  16. package/dist/node/routes-mcp.d.ts.map +1 -0
  17. package/dist/node/service.d.ts +1 -1
  18. package/dist/node/service.d.ts.map +1 -1
  19. package/dist/node/templates/errorAnalysisPrompt.d.ts.map +1 -1
  20. package/dist/node/templates/feedbackTemplate.d.ts +1 -6
  21. package/dist/node/templates/feedbackTemplate.d.ts.map +1 -1
  22. package/dist/node/templates/resourceAnalysisTemplate.d.ts +1 -6
  23. package/dist/node/templates/resourceAnalysisTemplate.d.ts.map +1 -1
  24. package/dist/node/templates/resourceSelectionTemplate.d.ts +1 -6
  25. package/dist/node/templates/resourceSelectionTemplate.d.ts.map +1 -1
  26. package/dist/node/templates/toolReasoningTemplate.d.ts +1 -6
  27. package/dist/node/templates/toolReasoningTemplate.d.ts.map +1 -1
  28. package/dist/node/templates/toolSelectionTemplate.d.ts +2 -7
  29. package/dist/node/templates/toolSelectionTemplate.d.ts.map +1 -1
  30. package/dist/node/tool-compatibility/integration-test.d.ts.map +1 -1
  31. package/dist/node/tool-compatibility/providers/openai.d.ts.map +1 -1
  32. package/dist/node/tool-compatibility/test-example.d.ts.map +1 -1
  33. package/dist/node/types.d.ts +1 -0
  34. package/dist/node/types.d.ts.map +1 -1
  35. package/dist/node/utils/error.d.ts.map +1 -1
  36. package/dist/node/utils/handler.d.ts.map +1 -1
  37. package/dist/node/utils/json.d.ts +1 -0
  38. package/dist/node/utils/json.d.ts.map +1 -1
  39. package/dist/node/utils/validation.d.ts.map +1 -1
  40. package/dist/node/utils/wrapper.d.ts.map +1 -1
  41. package/package.json +9 -8
  42. package/dist/node/actions/callToolAction.d.ts +0 -3
  43. package/dist/node/actions/callToolAction.d.ts.map +0 -1
  44. package/dist/node/actions/readResourceAction.d.ts +0 -3
  45. package/dist/node/actions/readResourceAction.d.ts.map +0 -1
  46. package/dist/node/generated/prompts/typescript/prompts.d.ts +0 -24
  47. package/dist/node/generated/prompts/typescript/prompts.d.ts.map +0 -1
  48. package/dist/tsconfig.build.tsbuildinfo +0 -1
package/README.md ADDED
@@ -0,0 +1,269 @@
1
+ # MCP Plugin for elizaOS
2
+
3
+ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-blue.svg)](https://conventionalcommits.org)
4
+
5
+ This plugin integrates the Model Context Protocol (MCP) with elizaOS, allowing agents to connect to multiple MCP servers and use their resources, prompts, and tools.
6
+
7
+ ## 🔍 What is MCP?
8
+
9
+ The [Model Context Protocol](https://modelcontextprotocol.io) (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. It provides a standardized way to connect LLMs with the context they need.
10
+
11
+ This plugin allows your elizaOS agents to access multiple MCP servers simultaneously, each providing different capabilities:
12
+
13
+ - **Resources**: Context and data for the agent to reference
14
+ - **Tools**: Functions for the agent to execute
15
+
16
+ ## 📦 Installation
17
+
18
+ Install the plugin in your elizaOS project:
19
+
20
+ - **npm**
21
+
22
+ ```bash
23
+ npm install @elizaos/plugin-mcp
24
+ ```
25
+
26
+ - **yarn**
27
+
28
+ ```bash
29
+ yarn add @elizaos/plugin-mcp
30
+ ```
31
+
32
+ - **bun**
33
+
34
+ ```bash
35
+ bun add @elizaos/plugin-mcp
36
+ ```
37
+
38
+ ## 🚀 Usage
39
+
40
+ 1. Add the plugin to your character configuration:
41
+
42
+ ```json
43
+ {
44
+ "name": "Your Character",
45
+ "plugins": ["@elizaos/plugin-mcp"],
46
+ "settings": {
47
+ "mcp": {
48
+ "servers": {
49
+ "github": {
50
+ "type": "stdio",
51
+ "command": "npx",
52
+ "args": ["-y", "@modelcontextprotocol/server-github"]
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ ## ⚙️ Configuration Options
61
+
62
+ MCP supports multiple transport types for connecting to servers. Each type has its own configuration options.
63
+
64
+ ### Transport Types
65
+
66
+ - **`streamable-http`** or **`http`** - Streamable HTTP transport (recommended)
67
+ - **`sse`** - Server-Sent Events transport
68
+ - **`stdio`** - Process-based transport using standard input/output
69
+
70
+ ### HTTP Transport Options (streamable-http, http, sse)
71
+
72
+ | Option | Type | Description |
73
+ | --------- | ------ | --------------------------------------------------- |
74
+ | `type` | string | Transport type: "streamable-http", "http", or "sse" |
75
+ | `url` | string | The URL of the HTTP/SSE endpoint |
76
+ | `timeout` | number | _Optional_ Timeout for connections |
77
+
78
+ ### stdio Transport Options
79
+
80
+ | Option | Type | Description |
81
+ | ----------------- | -------- | ------------------------------------------------------ |
82
+ | `type` | string | Must be "stdio" |
83
+ | `command` | string | _Optional_ The command to run the MCP server |
84
+ | `args` | string[] | _Optional_ Command-line arguments for the server |
85
+ | `env` | object | _Optional_ Environment variables to pass to the server |
86
+ | `cwd` | string | _Optional_ Working directory to run the server in |
87
+ | `timeoutInMillis` | number | _Optional_ Timeout in milliseconds for tool calls |
88
+
89
+ ### Example Configuration
90
+
91
+ ```json
92
+ {
93
+ "mcp": {
94
+ "servers": {
95
+ "my-http-server": {
96
+ "type": "streamable-http",
97
+ "url": "https://example.com/mcp"
98
+ },
99
+ "my-local-server": {
100
+ "type": "http",
101
+ "url": "http://localhost:3000",
102
+ "timeout": 30
103
+ },
104
+ "my-sse-server": {
105
+ "type": "sse",
106
+ "url": "http://localhost:8080"
107
+ },
108
+ "my-stdio-server": {
109
+ "type": "stdio",
110
+ "command": "mcp-server",
111
+ "args": ["--config", "config.json"],
112
+ "cwd": "/path/to/server",
113
+ "timeoutInMillis": 60000
114
+ }
115
+ },
116
+ "maxRetries": 3
117
+ }
118
+ }
119
+ ```
120
+
121
+ ## 🛠️ Using MCP Capabilities
122
+
123
+ Once configured, the plugin automatically exposes MCP servers' capabilities to your agent:
124
+
125
+ ### Context Provider
126
+
127
+ The plugin includes one provider that adds MCP capabilities to the agent's context:
128
+
129
+ 1. **`MCP`**: Lists available servers and their tools and resources
130
+
131
+ ### Actions
132
+
133
+ The plugin provides two actions for interacting with MCP servers:
134
+
135
+ 1. **`CALL_MCP_TOOL`**: Executes tools from connected MCP servers
136
+ 2. **`READ_MCP_RESOURCE`**: Accesses resources from connected MCP servers
137
+
138
+ ## 🔄 Plugin Flow
139
+
140
+ The following diagram illustrates the MCP plugin's flow for tool selection and execution:
141
+
142
+ ```mermaid
143
+ graph TD
144
+ %% Starting point - User request
145
+ start[User Request] --> action[CALL_MCP_TOOL Action]
146
+
147
+ %% MCP Server Validation
148
+ action --> check{MCP Servers Available?}
149
+ check -->|No| fail[Return No Tools Available]
150
+
151
+ %% Tool Selection Flow
152
+ check -->|Yes| state[Get MCP Provider Data]
153
+ state --> prompt[Create Tool Selection Prompt]
154
+
155
+ %% First Model Use - Tool Selection
156
+ prompt --> model1[Use Language Model for Tool Selection]
157
+ model1 --> parse[Parse Selection]
158
+ parse --> retry{Valid Selection?}
159
+
160
+ %% Second Model Use - Retry Selection
161
+ retry -->|No| feedback[Generate Feedback]
162
+ feedback --> model2[Use Language Model for Retry]
163
+ model2 --> parse
164
+
165
+ %% Tool Selection Result
166
+ retry -->|Yes| toolAvailable{Tool Available?}
167
+ toolAvailable -->|No| fallback[Fallback Response]
168
+
169
+ %% Tool Execution Flow
170
+ toolAvailable -->|Yes| callTool[Call MCP Tool]
171
+ callTool --> processResult[Process Tool Result]
172
+
173
+ %% Memory Creation
174
+ processResult --> createMemory[Create Memory Record]
175
+ createMemory --> reasoningPrompt[Create Reasoning Prompt]
176
+
177
+ %% Third Model Use - Response Generation
178
+ reasoningPrompt --> model3[Use Language Model for Response]
179
+ model3 --> respondToUser[Send Response to User]
180
+
181
+ %% Styling
182
+ classDef model fill:#f9f,stroke:#333,stroke-width:2px;
183
+ classDef decision fill:#bbf,stroke:#333,stroke-width:2px;
184
+ classDef output fill:#bfb,stroke:#333,stroke-width:2px;
185
+
186
+ class model1,model2,model3 model;
187
+ class check,retry,toolAvailable decision;
188
+ class respondToUser,fallback output;
189
+ ```
190
+
191
+ ## 📋 Example: Setting Up Multiple MCP Servers
192
+
193
+ Here's a complete example configuration with multiple MCP servers of both types:
194
+
195
+ ```json
196
+ {
197
+ "name": "Developer Assistant",
198
+ "plugins": ["@elizaos/plugin-mcp", "other-plugins"],
199
+ "settings": {
200
+ "mcp": {
201
+ "servers": {
202
+ "github": {
203
+ "type": "stdio",
204
+ "command": "npx",
205
+ "args": ["-y", "@modelcontextprotocol/server-github"],
206
+ "env": {
207
+ "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
208
+ }
209
+ },
210
+ "puppeteer": {
211
+ "type": "stdio",
212
+ "command": "npx",
213
+ "args": ["-y", "@modelcontextprotocol/server-puppeteer"]
214
+ },
215
+ "google-maps": {
216
+ "type": "stdio",
217
+ "command": "npx",
218
+ "args": ["-y", "@modelcontextprotocol/server-google-maps"],
219
+ "env": {
220
+ "GOOGLE_MAPS_API_KEY": "<YOUR_API_KEY>"
221
+ }
222
+ }
223
+ },
224
+ "maxRetries": 2
225
+ }
226
+ }
227
+ }
228
+ ```
229
+
230
+ ## 🔒 Security Considerations
231
+
232
+ Please be aware that MCP servers can execute arbitrary code, so only connect to servers you trust.
233
+
234
+ ## 🔍 Troubleshooting
235
+
236
+ If you encounter issues with the MCP plugin:
237
+
238
+ 1. Check that your MCP servers are correctly configured and running
239
+ 2. Ensure the commands are accessible in the elizaOS environment
240
+ 3. Review the logs for connection errors
241
+ 4. Verify that the plugin is properly loaded in your character configuration
242
+
243
+ ## 👥 Contributing
244
+
245
+ Thanks for considering contributing to our project!
246
+
247
+ ### How to Contribute
248
+
249
+ 1. Fork the repository.
250
+ 2. Create a new branch: `git checkout -b feature-branch-name`.
251
+ 3. Make your changes.
252
+ 4. Commit your changes using conventional commits.
253
+ 5. Push to your fork and submit a pull request.
254
+
255
+ ### Commit Guidelines
256
+
257
+ We use [Conventional Commits](https://www.conventionalcommits.org/) for our commit messages:
258
+
259
+ - `test`: 💍 Adding missing tests
260
+ - `feat`: 🎸 A new feature
261
+ - `fix`: 🐛 A bug fix
262
+ - `chore`: 🤖 Build process or auxiliary tool changes
263
+ - `docs`: ✏️ Documentation only changes
264
+ - `refactor`: 💡 A code change that neither fixes a bug or adds a feature
265
+ - `style`: 💄 Markup, white-space, formatting, missing semi-colons...
266
+
267
+ ## 📄 License
268
+
269
+ This plugin is released under the same license as elizaOS.