mcp-use 1.13.3-canary.0 → 1.13.3-canary.2
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.
- package/README.md +183 -183
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-JBMSENSD.js → chunk-5GY57XQH.js} +2 -2
- package/dist/{chunk-YUVTKMAD.js → chunk-7PET6NKL.js} +19 -6
- package/dist/{chunk-VOHJI524.js → chunk-HDKVGBFQ.js} +1 -1
- package/dist/{chunk-UXX3SNB2.js → chunk-IZ3ZQGT2.js} +2 -2
- package/dist/{chunk-DWUMEEOX.js → chunk-J6VCCQRH.js} +4 -4
- package/dist/{chunk-EP4Z2NNG.js → chunk-JEUOIQXN.js} +1 -1
- package/dist/chunk-K6N2VH5H.js +2663 -0
- package/dist/chunk-MIGRXQ7Q.js +1343 -0
- package/dist/{chunk-EB2JSKX5.js → chunk-OB2FA2OW.js} +1 -1
- package/dist/{chunk-BJCZQJLJ.js → chunk-OV7M5WAZ.js} +1 -1
- package/dist/{chunk-BLI6NF5B.js → chunk-PIUHQN4S.js} +1 -1
- package/dist/chunk-R5F6WTGY.js +3106 -0
- package/dist/{chunk-W724P3AE.js → chunk-R5VASJHS.js} +1 -1
- package/dist/index.cjs +15 -2
- package/dist/index.js +47 -47
- package/dist/src/agents/index.cjs +1 -1
- package/dist/src/agents/index.js +5 -5
- package/dist/src/browser.cjs +1 -1
- package/dist/src/browser.js +15 -15
- package/dist/src/client.cjs +1 -1
- package/dist/src/client.js +5 -5
- package/dist/src/react/index.cjs +15 -2
- package/dist/src/react/index.js +8 -8
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +1 -1
- package/dist/src/server/index.js +5 -5
- package/dist/src/version.d.ts +1 -1
- package/dist/{tool-execution-helpers-GSTAIVWP.js → tool-execution-helpers-DJH55ZKE.js} +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
|
|
34
34
|
## 📦 mcp-use Ecosystem
|
|
35
35
|
|
|
36
|
-
| Package
|
|
37
|
-
|
|
|
38
|
-
| **mcp-use**
|
|
39
|
-
| [@mcp-use/cli](https://github.com/mcp-use/mcp-use/tree/main/packages/cli) | Build tool for MCP apps with UI widgets | [](https://www.npmjs.com/package/@mcp-use/cli) |
|
|
40
|
-
| [@mcp-use/inspector](https://github.com/mcp-use/mcp-use/tree/main/packages/inspector) | Web-based MCP server inspector and debugger | [](https://www.npmjs.com/package/@mcp-use/inspector) |
|
|
41
|
-
| [create-mcp-use-app](https://github.com/mcp-use/mcp-use/tree/main/packages/create-mcp-use-app) | Create MCP apps with one command | [](https://www.npmjs.com/package/create-mcp-use-app) |
|
|
36
|
+
| Package | Description | Version |
|
|
37
|
+
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
38
|
+
| **mcp-use** | Core framework for MCP clients and servers | [](https://www.npmjs.com/package/mcp-use) |
|
|
39
|
+
| [@mcp-use/cli](https://github.com/mcp-use/mcp-use/tree/main/libraries/typescript/packages/cli) | Build tool for MCP apps with UI widgets | [](https://www.npmjs.com/package/@mcp-use/cli) |
|
|
40
|
+
| [@mcp-use/inspector](https://github.com/mcp-use/mcp-use/tree/main/libraries/typescript/packages/inspector) | Web-based MCP server inspector and debugger | [](https://www.npmjs.com/package/@mcp-use/inspector) |
|
|
41
|
+
| [create-mcp-use-app](https://github.com/mcp-use/mcp-use/tree/main/libraries/typescript/packages/create-mcp-use-app) | Create MCP apps with one command | [](https://www.npmjs.com/package/create-mcp-use-app) |
|
|
42
42
|
|
|
43
43
|
---
|
|
44
44
|
|
|
@@ -85,33 +85,33 @@ OPENAI_API_KEY=your_api_key
|
|
|
85
85
|
### Basic Usage
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
|
-
import { ChatOpenAI } from
|
|
89
|
-
import { MCPAgent, MCPClient } from
|
|
90
|
-
import
|
|
88
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
89
|
+
import { MCPAgent, MCPClient } from "mcp-use";
|
|
90
|
+
import "dotenv/config";
|
|
91
91
|
|
|
92
92
|
async function main() {
|
|
93
93
|
// 1. Configure MCP servers
|
|
94
94
|
const config = {
|
|
95
95
|
mcpServers: {
|
|
96
|
-
playwright: { command:
|
|
96
|
+
playwright: { command: "npx", args: ["@playwright/mcp@latest"] },
|
|
97
97
|
},
|
|
98
|
-
}
|
|
99
|
-
const client = MCPClient.fromDict(config)
|
|
98
|
+
};
|
|
99
|
+
const client = MCPClient.fromDict(config);
|
|
100
100
|
|
|
101
101
|
// 2. Create LLM
|
|
102
|
-
const llm = new ChatOpenAI({ modelName:
|
|
102
|
+
const llm = new ChatOpenAI({ modelName: "gpt-4o" });
|
|
103
103
|
|
|
104
104
|
// 3. Instantiate agent
|
|
105
|
-
const agent = new MCPAgent({ llm, client, maxSteps: 20 })
|
|
105
|
+
const agent = new MCPAgent({ llm, client, maxSteps: 20 });
|
|
106
106
|
|
|
107
107
|
// 4. Run query
|
|
108
108
|
const result = await agent.run(
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
console.log(
|
|
109
|
+
"Find the best restaurant in Tokyo using Google Search"
|
|
110
|
+
);
|
|
111
|
+
console.log("Result:", result);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
main().catch(console.error)
|
|
114
|
+
main().catch(console.error);
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
---
|
|
@@ -127,8 +127,8 @@ The `MCPAgent` class provides several methods for executing queries with differe
|
|
|
127
127
|
Executes a query and returns the final result as a string.
|
|
128
128
|
|
|
129
129
|
```ts
|
|
130
|
-
const result = await agent.run(
|
|
131
|
-
console.log(result)
|
|
130
|
+
const result = await agent.run("What tools are available?");
|
|
131
|
+
console.log(result);
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
#### `stream(query: string, maxSteps?: number): AsyncGenerator<AgentStep, string, void>`
|
|
@@ -136,10 +136,10 @@ console.log(result)
|
|
|
136
136
|
Yields intermediate steps during execution, providing visibility into the agent's reasoning process.
|
|
137
137
|
|
|
138
138
|
```ts
|
|
139
|
-
const stream = agent.stream(
|
|
139
|
+
const stream = agent.stream("Search for restaurants in Tokyo");
|
|
140
140
|
for await (const step of stream) {
|
|
141
|
-
console.log(`Tool: ${step.action.tool}, Input: ${step.action.toolInput}`)
|
|
142
|
-
console.log(`Result: ${step.observation}`)
|
|
141
|
+
console.log(`Tool: ${step.action.tool}, Input: ${step.action.toolInput}`);
|
|
142
|
+
console.log(`Result: ${step.observation}`);
|
|
143
143
|
}
|
|
144
144
|
```
|
|
145
145
|
|
|
@@ -148,22 +148,22 @@ for await (const step of stream) {
|
|
|
148
148
|
Yields fine-grained LangChain StreamEvent objects, enabling token-by-token streaming and detailed event tracking.
|
|
149
149
|
|
|
150
150
|
```ts
|
|
151
|
-
const eventStream = agent.streamEvents(
|
|
151
|
+
const eventStream = agent.streamEvents("What is the weather today?");
|
|
152
152
|
for await (const event of eventStream) {
|
|
153
153
|
// Handle different event types
|
|
154
154
|
switch (event.event) {
|
|
155
|
-
case
|
|
155
|
+
case "on_chat_model_stream":
|
|
156
156
|
// Token-by-token streaming from the LLM
|
|
157
157
|
if (event.data?.chunk?.content) {
|
|
158
|
-
process.stdout.write(event.data.chunk.content)
|
|
158
|
+
process.stdout.write(event.data.chunk.content);
|
|
159
159
|
}
|
|
160
|
-
break
|
|
161
|
-
case
|
|
162
|
-
console.log(`\nTool started: ${event.name}`)
|
|
163
|
-
break
|
|
164
|
-
case
|
|
165
|
-
console.log(`Tool completed: ${event.name}`)
|
|
166
|
-
break
|
|
160
|
+
break;
|
|
161
|
+
case "on_tool_start":
|
|
162
|
+
console.log(`\nTool started: ${event.name}`);
|
|
163
|
+
break;
|
|
164
|
+
case "on_tool_end":
|
|
165
|
+
console.log(`Tool completed: ${event.name}`);
|
|
166
|
+
break;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
```
|
|
@@ -187,66 +187,66 @@ npm install ai @langchain/anthropic
|
|
|
187
187
|
### Basic Usage
|
|
188
188
|
|
|
189
189
|
```ts
|
|
190
|
-
import { ChatAnthropic } from
|
|
191
|
-
import { createTextStreamResponse } from
|
|
190
|
+
import { ChatAnthropic } from "@langchain/anthropic";
|
|
191
|
+
import { createTextStreamResponse } from "ai";
|
|
192
192
|
import {
|
|
193
193
|
createReadableStreamFromGenerator,
|
|
194
194
|
MCPAgent,
|
|
195
195
|
MCPClient,
|
|
196
196
|
streamEventsToAISDK,
|
|
197
|
-
} from
|
|
197
|
+
} from "mcp-use";
|
|
198
198
|
|
|
199
199
|
async function createApiHandler() {
|
|
200
200
|
const config = {
|
|
201
201
|
mcpServers: {
|
|
202
202
|
everything: {
|
|
203
|
-
command:
|
|
204
|
-
args: [
|
|
203
|
+
command: "npx",
|
|
204
|
+
args: ["-y", "@modelcontextprotocol/server-everything"],
|
|
205
205
|
},
|
|
206
206
|
},
|
|
207
|
-
}
|
|
207
|
+
};
|
|
208
208
|
|
|
209
|
-
const client = new MCPClient(config)
|
|
210
|
-
const llm = new ChatAnthropic({ model:
|
|
211
|
-
const agent = new MCPAgent({ llm, client, maxSteps: 5 })
|
|
209
|
+
const client = new MCPClient(config);
|
|
210
|
+
const llm = new ChatAnthropic({ model: "claude-sonnet-4-20250514" });
|
|
211
|
+
const agent = new MCPAgent({ llm, client, maxSteps: 5 });
|
|
212
212
|
|
|
213
213
|
return async (request: { prompt: string }) => {
|
|
214
|
-
const streamEvents = agent.streamEvents(request.prompt)
|
|
215
|
-
const aiSDKStream = streamEventsToAISDK(streamEvents)
|
|
216
|
-
const readableStream = createReadableStreamFromGenerator(aiSDKStream)
|
|
214
|
+
const streamEvents = agent.streamEvents(request.prompt);
|
|
215
|
+
const aiSDKStream = streamEventsToAISDK(streamEvents);
|
|
216
|
+
const readableStream = createReadableStreamFromGenerator(aiSDKStream);
|
|
217
217
|
|
|
218
|
-
return createTextStreamResponse({ textStream: readableStream })
|
|
219
|
-
}
|
|
218
|
+
return createTextStreamResponse({ textStream: readableStream });
|
|
219
|
+
};
|
|
220
220
|
}
|
|
221
221
|
```
|
|
222
222
|
|
|
223
223
|
### Enhanced Usage with Tool Visibility
|
|
224
224
|
|
|
225
225
|
```ts
|
|
226
|
-
import { streamEventsToAISDKWithTools } from
|
|
226
|
+
import { streamEventsToAISDKWithTools } from "mcp-use";
|
|
227
227
|
|
|
228
228
|
async function createEnhancedApiHandler() {
|
|
229
229
|
const config = {
|
|
230
230
|
mcpServers: {
|
|
231
231
|
everything: {
|
|
232
|
-
command:
|
|
233
|
-
args: [
|
|
232
|
+
command: "npx",
|
|
233
|
+
args: ["-y", "@modelcontextprotocol/server-everything"],
|
|
234
234
|
},
|
|
235
235
|
},
|
|
236
|
-
}
|
|
236
|
+
};
|
|
237
237
|
|
|
238
|
-
const client = new MCPClient(config)
|
|
239
|
-
const llm = new ChatAnthropic({ model:
|
|
240
|
-
const agent = new MCPAgent({ llm, client, maxSteps: 8 })
|
|
238
|
+
const client = new MCPClient(config);
|
|
239
|
+
const llm = new ChatAnthropic({ model: "claude-sonnet-4-20250514" });
|
|
240
|
+
const agent = new MCPAgent({ llm, client, maxSteps: 8 });
|
|
241
241
|
|
|
242
242
|
return async (request: { prompt: string }) => {
|
|
243
|
-
const streamEvents = agent.streamEvents(request.prompt)
|
|
243
|
+
const streamEvents = agent.streamEvents(request.prompt);
|
|
244
244
|
// Enhanced stream includes tool usage notifications
|
|
245
|
-
const enhancedStream = streamEventsToAISDKWithTools(streamEvents)
|
|
246
|
-
const readableStream = createReadableStreamFromGenerator(enhancedStream)
|
|
245
|
+
const enhancedStream = streamEventsToAISDKWithTools(streamEvents);
|
|
246
|
+
const readableStream = createReadableStreamFromGenerator(enhancedStream);
|
|
247
247
|
|
|
248
|
-
return createTextStreamResponse({ textStream: readableStream })
|
|
249
|
-
}
|
|
248
|
+
return createTextStreamResponse({ textStream: readableStream });
|
|
249
|
+
};
|
|
250
250
|
}
|
|
251
251
|
```
|
|
252
252
|
|
|
@@ -254,39 +254,39 @@ async function createEnhancedApiHandler() {
|
|
|
254
254
|
|
|
255
255
|
```ts
|
|
256
256
|
// pages/api/chat.ts or app/api/chat/route.ts
|
|
257
|
-
import { ChatAnthropic } from
|
|
258
|
-
import { createTextStreamResponse } from
|
|
257
|
+
import { ChatAnthropic } from "@langchain/anthropic";
|
|
258
|
+
import { createTextStreamResponse } from "ai";
|
|
259
259
|
import {
|
|
260
260
|
createReadableStreamFromGenerator,
|
|
261
261
|
MCPAgent,
|
|
262
262
|
MCPClient,
|
|
263
263
|
streamEventsToAISDK,
|
|
264
|
-
} from
|
|
264
|
+
} from "mcp-use";
|
|
265
265
|
|
|
266
266
|
export async function POST(req: Request) {
|
|
267
|
-
const { prompt } = await req.json()
|
|
267
|
+
const { prompt } = await req.json();
|
|
268
268
|
|
|
269
269
|
const config = {
|
|
270
270
|
mcpServers: {
|
|
271
271
|
everything: {
|
|
272
|
-
command:
|
|
273
|
-
args: [
|
|
272
|
+
command: "npx",
|
|
273
|
+
args: ["-y", "@modelcontextprotocol/server-everything"],
|
|
274
274
|
},
|
|
275
275
|
},
|
|
276
|
-
}
|
|
276
|
+
};
|
|
277
277
|
|
|
278
|
-
const client = new MCPClient(config)
|
|
279
|
-
const llm = new ChatAnthropic({ model:
|
|
280
|
-
const agent = new MCPAgent({ llm, client, maxSteps: 10 })
|
|
278
|
+
const client = new MCPClient(config);
|
|
279
|
+
const llm = new ChatAnthropic({ model: "claude-sonnet-4-20250514" });
|
|
280
|
+
const agent = new MCPAgent({ llm, client, maxSteps: 10 });
|
|
281
281
|
|
|
282
282
|
try {
|
|
283
|
-
const streamEvents = agent.streamEvents(prompt)
|
|
284
|
-
const aiSDKStream = streamEventsToAISDK(streamEvents)
|
|
285
|
-
const readableStream = createReadableStreamFromGenerator(aiSDKStream)
|
|
283
|
+
const streamEvents = agent.streamEvents(prompt);
|
|
284
|
+
const aiSDKStream = streamEventsToAISDK(streamEvents);
|
|
285
|
+
const readableStream = createReadableStreamFromGenerator(aiSDKStream);
|
|
286
286
|
|
|
287
|
-
return createTextStreamResponse({ textStream: readableStream })
|
|
287
|
+
return createTextStreamResponse({ textStream: readableStream });
|
|
288
288
|
} finally {
|
|
289
|
-
await client.closeAllSessions()
|
|
289
|
+
await client.closeAllSessions();
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
```
|
|
@@ -295,12 +295,12 @@ export async function POST(req: Request) {
|
|
|
295
295
|
|
|
296
296
|
```tsx
|
|
297
297
|
// components/Chat.tsx
|
|
298
|
-
import { useCompletion } from
|
|
298
|
+
import { useCompletion } from "ai/react";
|
|
299
299
|
|
|
300
300
|
export function Chat() {
|
|
301
301
|
const { completion, input, handleInputChange, handleSubmit } = useCompletion({
|
|
302
|
-
api:
|
|
303
|
-
})
|
|
302
|
+
api: "/api/chat",
|
|
303
|
+
});
|
|
304
304
|
|
|
305
305
|
return (
|
|
306
306
|
<div>
|
|
@@ -313,7 +313,7 @@ export function Chat() {
|
|
|
313
313
|
/>
|
|
314
314
|
</form>
|
|
315
315
|
</div>
|
|
316
|
-
)
|
|
316
|
+
);
|
|
317
317
|
}
|
|
318
318
|
```
|
|
319
319
|
|
|
@@ -345,39 +345,39 @@ LANGFUSE_HOST=https://cloud.langfuse.com # or your self-hosted instance
|
|
|
345
345
|
```ts
|
|
346
346
|
// Set custom metadata for the current execution
|
|
347
347
|
agent.setMetadata({
|
|
348
|
-
userId:
|
|
349
|
-
sessionId:
|
|
350
|
-
environment:
|
|
351
|
-
})
|
|
348
|
+
userId: "user123",
|
|
349
|
+
sessionId: "session456",
|
|
350
|
+
environment: "production",
|
|
351
|
+
});
|
|
352
352
|
|
|
353
353
|
// Set tags for better organization
|
|
354
|
-
agent.setTags([
|
|
354
|
+
agent.setTags(["production", "user-query", "tool-discovery"]);
|
|
355
355
|
|
|
356
356
|
// Run query with metadata and tags
|
|
357
|
-
const result = await agent.run(
|
|
357
|
+
const result = await agent.run("Search for restaurants in Tokyo");
|
|
358
358
|
```
|
|
359
359
|
|
|
360
360
|
#### Monitoring Agent Performance
|
|
361
361
|
|
|
362
362
|
```ts
|
|
363
363
|
// Stream events for detailed monitoring
|
|
364
|
-
const eventStream = agent.streamEvents(
|
|
364
|
+
const eventStream = agent.streamEvents("Complex multi-step query");
|
|
365
365
|
|
|
366
366
|
for await (const event of eventStream) {
|
|
367
367
|
// Monitor different event types
|
|
368
368
|
switch (event.event) {
|
|
369
|
-
case
|
|
370
|
-
console.log(
|
|
371
|
-
break
|
|
372
|
-
case
|
|
373
|
-
console.log(
|
|
374
|
-
break
|
|
375
|
-
case
|
|
376
|
-
console.log(
|
|
377
|
-
break
|
|
378
|
-
case
|
|
379
|
-
console.log(
|
|
380
|
-
break
|
|
369
|
+
case "on_llm_start":
|
|
370
|
+
console.log("LLM call started:", event.data);
|
|
371
|
+
break;
|
|
372
|
+
case "on_tool_start":
|
|
373
|
+
console.log("Tool execution started:", event.name, event.data);
|
|
374
|
+
break;
|
|
375
|
+
case "on_tool_end":
|
|
376
|
+
console.log("Tool execution completed:", event.name, event.data);
|
|
377
|
+
break;
|
|
378
|
+
case "on_chain_end":
|
|
379
|
+
console.log("Agent execution completed:", event.data);
|
|
380
|
+
break;
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
```
|
|
@@ -391,7 +391,7 @@ const agent = new MCPAgent({
|
|
|
391
391
|
llm,
|
|
392
392
|
client,
|
|
393
393
|
observe: false,
|
|
394
|
-
})
|
|
394
|
+
});
|
|
395
395
|
```
|
|
396
396
|
|
|
397
397
|
---
|
|
@@ -414,9 +414,9 @@ You can store servers in a JSON file:
|
|
|
414
414
|
Load it:
|
|
415
415
|
|
|
416
416
|
```ts
|
|
417
|
-
import { MCPClient } from
|
|
417
|
+
import { MCPClient } from "mcp-use";
|
|
418
418
|
|
|
419
|
-
const client = MCPClient.fromConfigFile(
|
|
419
|
+
const client = MCPClient.fromConfigFile("./mcp-config.json");
|
|
420
420
|
```
|
|
421
421
|
|
|
422
422
|
---
|
|
@@ -463,13 +463,13 @@ See the [examples README](./examples/README.md) for detailed documentation and p
|
|
|
463
463
|
```ts
|
|
464
464
|
const config = {
|
|
465
465
|
mcpServers: {
|
|
466
|
-
airbnb: { command:
|
|
467
|
-
playwright: { command:
|
|
466
|
+
airbnb: { command: "npx", args: ["@openbnb/mcp-server-airbnb"] },
|
|
467
|
+
playwright: { command: "npx", args: ["@playwright/mcp@latest"] },
|
|
468
468
|
},
|
|
469
|
-
}
|
|
470
|
-
const client = MCPClient.fromDict(config)
|
|
471
|
-
const agent = new MCPAgent({ llm, client, useServerManager: true })
|
|
472
|
-
await agent.run(
|
|
469
|
+
};
|
|
470
|
+
const client = MCPClient.fromDict(config);
|
|
471
|
+
const agent = new MCPAgent({ llm, client, useServerManager: true });
|
|
472
|
+
await agent.run("Search Airbnb in Barcelona, then Google restaurants nearby");
|
|
473
473
|
```
|
|
474
474
|
|
|
475
475
|
---
|
|
@@ -480,8 +480,8 @@ await agent.run('Search Airbnb in Barcelona, then Google restaurants nearby')
|
|
|
480
480
|
const agent = new MCPAgent({
|
|
481
481
|
llm,
|
|
482
482
|
client,
|
|
483
|
-
disallowedTools: [
|
|
484
|
-
})
|
|
483
|
+
disallowedTools: ["file_system", "network"],
|
|
484
|
+
});
|
|
485
485
|
```
|
|
486
486
|
|
|
487
487
|
---
|
|
@@ -493,48 +493,48 @@ Beyond being a powerful MCP client, mcp-use also provides a complete server fram
|
|
|
493
493
|
### Quick Server Setup
|
|
494
494
|
|
|
495
495
|
```ts
|
|
496
|
-
import { MCPServer } from
|
|
496
|
+
import { MCPServer } from "mcp-use/server";
|
|
497
497
|
|
|
498
498
|
// Create your MCP server
|
|
499
499
|
const server = new MCPServer({
|
|
500
|
-
name:
|
|
501
|
-
version:
|
|
502
|
-
description:
|
|
503
|
-
})
|
|
500
|
+
name: "my-awesome-server",
|
|
501
|
+
version: "1.0.0",
|
|
502
|
+
description: "My MCP server with tools, resources, and prompts",
|
|
503
|
+
});
|
|
504
504
|
|
|
505
505
|
// Define tools
|
|
506
|
-
server.tool(
|
|
507
|
-
description:
|
|
506
|
+
server.tool("search_web", {
|
|
507
|
+
description: "Search the web for information",
|
|
508
508
|
parameters: z.object({
|
|
509
|
-
query: z.string().describe(
|
|
509
|
+
query: z.string().describe("Search query"),
|
|
510
510
|
}),
|
|
511
511
|
execute: async (args) => {
|
|
512
512
|
// Your tool implementation
|
|
513
|
-
return { results: await performSearch(args.query) }
|
|
513
|
+
return { results: await performSearch(args.query) };
|
|
514
514
|
},
|
|
515
|
-
})
|
|
515
|
+
});
|
|
516
516
|
|
|
517
517
|
// Define resources
|
|
518
|
-
server.resource(
|
|
519
|
-
description:
|
|
520
|
-
uri:
|
|
521
|
-
mimeType:
|
|
518
|
+
server.resource("config", {
|
|
519
|
+
description: "Application configuration",
|
|
520
|
+
uri: "config://settings",
|
|
521
|
+
mimeType: "application/json",
|
|
522
522
|
fetch: async () => {
|
|
523
|
-
return JSON.stringify(await getConfig(), null, 2)
|
|
523
|
+
return JSON.stringify(await getConfig(), null, 2);
|
|
524
524
|
},
|
|
525
|
-
})
|
|
525
|
+
});
|
|
526
526
|
|
|
527
527
|
// Define prompts
|
|
528
|
-
server.prompt(
|
|
529
|
-
description:
|
|
530
|
-
arguments: [{ name:
|
|
528
|
+
server.prompt("code_review", {
|
|
529
|
+
description: "Review code for best practices",
|
|
530
|
+
arguments: [{ name: "code", description: "Code to review", required: true }],
|
|
531
531
|
render: async (args) => {
|
|
532
|
-
return `Please review this code:\n\n${args.code}
|
|
532
|
+
return `Please review this code:\n\n${args.code}`;
|
|
533
533
|
},
|
|
534
|
-
})
|
|
534
|
+
});
|
|
535
535
|
|
|
536
536
|
// Start the server
|
|
537
|
-
server.listen(3000)
|
|
537
|
+
server.listen(3000);
|
|
538
538
|
// 🎉 Inspector automatically available at http://localhost:3000/inspector
|
|
539
539
|
// 🚀 MCP endpoint available at http://localhost:3000/mcp
|
|
540
540
|
```
|
|
@@ -558,32 +558,32 @@ mcp-use provides a unified `uiResource()` method for registering interactive UI
|
|
|
558
558
|
#### Quick Start
|
|
559
559
|
|
|
560
560
|
```ts
|
|
561
|
-
import { MCPServer } from
|
|
561
|
+
import { MCPServer } from "mcp-use/server";
|
|
562
562
|
|
|
563
|
-
const server = new MCPServer({ name:
|
|
563
|
+
const server = new MCPServer({ name: "my-server", version: "1.0.0" });
|
|
564
564
|
|
|
565
565
|
// Register a widget - creates both tool and resource automatically
|
|
566
566
|
server.uiResource({
|
|
567
|
-
type:
|
|
568
|
-
name:
|
|
569
|
-
widget:
|
|
570
|
-
title:
|
|
571
|
-
description:
|
|
567
|
+
type: "externalUrl",
|
|
568
|
+
name: "kanban-board",
|
|
569
|
+
widget: "kanban-board",
|
|
570
|
+
title: "Kanban Board",
|
|
571
|
+
description: "Interactive task management board",
|
|
572
572
|
props: {
|
|
573
573
|
initialTasks: {
|
|
574
|
-
type:
|
|
575
|
-
description:
|
|
574
|
+
type: "array",
|
|
575
|
+
description: "Initial tasks",
|
|
576
576
|
required: false,
|
|
577
577
|
},
|
|
578
578
|
theme: {
|
|
579
|
-
type:
|
|
580
|
-
default:
|
|
579
|
+
type: "string",
|
|
580
|
+
default: "light",
|
|
581
581
|
},
|
|
582
582
|
},
|
|
583
|
-
size: [
|
|
584
|
-
})
|
|
583
|
+
size: ["900px", "600px"],
|
|
584
|
+
});
|
|
585
585
|
|
|
586
|
-
server.listen(3000)
|
|
586
|
+
server.listen(3000);
|
|
587
587
|
```
|
|
588
588
|
|
|
589
589
|
This automatically creates:
|
|
@@ -598,11 +598,11 @@ Serve widgets from your filesystem via iframe:
|
|
|
598
598
|
|
|
599
599
|
```ts
|
|
600
600
|
server.uiResource({
|
|
601
|
-
type:
|
|
602
|
-
name:
|
|
603
|
-
widget:
|
|
604
|
-
props: { userId: { type:
|
|
605
|
-
})
|
|
601
|
+
type: "externalUrl",
|
|
602
|
+
name: "dashboard",
|
|
603
|
+
widget: "dashboard",
|
|
604
|
+
props: { userId: { type: "string", required: true } },
|
|
605
|
+
});
|
|
606
606
|
```
|
|
607
607
|
|
|
608
608
|
**2. Raw HTML**
|
|
@@ -610,15 +610,15 @@ Direct HTML content rendering:
|
|
|
610
610
|
|
|
611
611
|
```ts
|
|
612
612
|
server.uiResource({
|
|
613
|
-
type:
|
|
614
|
-
name:
|
|
613
|
+
type: "rawHtml",
|
|
614
|
+
name: "welcome-card",
|
|
615
615
|
htmlContent: `
|
|
616
616
|
<!DOCTYPE html>
|
|
617
617
|
<html>
|
|
618
618
|
<body><h1>Welcome!</h1></body>
|
|
619
619
|
</html>
|
|
620
620
|
`,
|
|
621
|
-
})
|
|
621
|
+
});
|
|
622
622
|
```
|
|
623
623
|
|
|
624
624
|
**3. Remote DOM**
|
|
@@ -626,15 +626,15 @@ Interactive components using MCP-UI React components:
|
|
|
626
626
|
|
|
627
627
|
```ts
|
|
628
628
|
server.uiResource({
|
|
629
|
-
type:
|
|
630
|
-
name:
|
|
629
|
+
type: "remoteDom",
|
|
630
|
+
name: "quick-poll",
|
|
631
631
|
script: `
|
|
632
632
|
const button = document.createElement('ui-button');
|
|
633
633
|
button.setAttribute('label', 'Vote');
|
|
634
634
|
root.appendChild(button);
|
|
635
635
|
`,
|
|
636
|
-
framework:
|
|
637
|
-
})
|
|
636
|
+
framework: "react",
|
|
637
|
+
});
|
|
638
638
|
```
|
|
639
639
|
|
|
640
640
|
#### Get Started with Templates
|
|
@@ -655,24 +655,24 @@ mcp-use supports building custom UI widgets for your MCP tools using React:
|
|
|
655
655
|
|
|
656
656
|
```tsx
|
|
657
657
|
// resources/task-manager.tsx
|
|
658
|
-
import React, { useState } from
|
|
659
|
-
import { useMcp } from
|
|
658
|
+
import React, { useState } from "react";
|
|
659
|
+
import { useMcp } from "mcp-use/react";
|
|
660
660
|
|
|
661
661
|
export default function TaskManager() {
|
|
662
|
-
const { callTool } = useMcp()
|
|
663
|
-
const [tasks, setTasks] = useState<Task[]>([])
|
|
662
|
+
const { callTool } = useMcp();
|
|
663
|
+
const [tasks, setTasks] = useState<Task[]>([]);
|
|
664
664
|
|
|
665
665
|
const addTask = async (title: string) => {
|
|
666
|
-
const result = await callTool(
|
|
667
|
-
setTasks([...tasks, result])
|
|
668
|
-
}
|
|
666
|
+
const result = await callTool("create_task", { title });
|
|
667
|
+
setTasks([...tasks, result]);
|
|
668
|
+
};
|
|
669
669
|
|
|
670
670
|
return (
|
|
671
671
|
<div>
|
|
672
672
|
<h1>Task Manager</h1>
|
|
673
673
|
{/* Your UI implementation */}
|
|
674
674
|
</div>
|
|
675
|
-
)
|
|
675
|
+
);
|
|
676
676
|
}
|
|
677
677
|
```
|
|
678
678
|
|
|
@@ -693,29 +693,29 @@ npx @mcp-use/cli start
|
|
|
693
693
|
|
|
694
694
|
```ts
|
|
695
695
|
const server = new MCPServer({
|
|
696
|
-
name:
|
|
697
|
-
version:
|
|
698
|
-
description:
|
|
696
|
+
name: "advanced-server",
|
|
697
|
+
version: "1.0.0",
|
|
698
|
+
description: "Advanced MCP server with custom configuration",
|
|
699
699
|
// Custom inspector path (default: /inspector)
|
|
700
|
-
inspectorPath:
|
|
700
|
+
inspectorPath: "/debug",
|
|
701
701
|
// Custom MCP endpoint (default: /mcp)
|
|
702
|
-
mcpPath:
|
|
702
|
+
mcpPath: "/api/mcp",
|
|
703
703
|
// Enable CORS for browser access
|
|
704
704
|
cors: {
|
|
705
|
-
origin: [
|
|
705
|
+
origin: ["http://localhost:3000", "https://myapp.com"],
|
|
706
706
|
credentials: true,
|
|
707
707
|
},
|
|
708
708
|
// OAuth configuration
|
|
709
709
|
oauth: {
|
|
710
710
|
clientId: process.env.OAUTH_CLIENT_ID,
|
|
711
711
|
clientSecret: process.env.OAUTH_CLIENT_SECRET,
|
|
712
|
-
authorizationUrl:
|
|
713
|
-
tokenUrl:
|
|
714
|
-
scopes: [
|
|
712
|
+
authorizationUrl: "https://api.example.com/oauth/authorize",
|
|
713
|
+
tokenUrl: "https://api.example.com/oauth/token",
|
|
714
|
+
scopes: ["read", "write"],
|
|
715
715
|
},
|
|
716
716
|
// Custom middleware
|
|
717
717
|
middleware: [authenticationMiddleware, rateLimitingMiddleware],
|
|
718
|
-
})
|
|
718
|
+
});
|
|
719
719
|
```
|
|
720
720
|
|
|
721
721
|
### Server Deployment
|
|
@@ -739,24 +739,24 @@ docker run -p 3000:3000 my-mcp-server
|
|
|
739
739
|
You can also integrate MCP server into existing Express applications:
|
|
740
740
|
|
|
741
741
|
```ts
|
|
742
|
-
import express from
|
|
743
|
-
import { mountMCPServer } from
|
|
742
|
+
import express from "express";
|
|
743
|
+
import { mountMCPServer } from "mcp-use/server";
|
|
744
744
|
|
|
745
|
-
const app = express()
|
|
745
|
+
const app = express();
|
|
746
746
|
|
|
747
747
|
// Your existing routes
|
|
748
|
-
app.get(
|
|
748
|
+
app.get("/api/health", (req, res) => res.send("OK"));
|
|
749
749
|
|
|
750
750
|
// Mount MCP server
|
|
751
751
|
const mcpServer = new MCPServer({
|
|
752
|
-
name:
|
|
752
|
+
name: "integrated-server",
|
|
753
753
|
/* ... */
|
|
754
|
-
})
|
|
754
|
+
});
|
|
755
755
|
mountMCPServer(app, mcpServer, {
|
|
756
|
-
basePath:
|
|
757
|
-
})
|
|
756
|
+
basePath: "/mcp-service", // Optional custom base path
|
|
757
|
+
});
|
|
758
758
|
|
|
759
|
-
app.listen(3000)
|
|
759
|
+
app.listen(3000);
|
|
760
760
|
// Inspector at: http://localhost:3000/mcp-service/inspector
|
|
761
761
|
// MCP endpoint: http://localhost:3000/mcp-service/mcp
|
|
762
762
|
```
|