mcp-use 1.0.0 → 1.0.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 +190 -2
- package/dist/{chunk-4DEFXVWT.js → chunk-CWWNPIJZ.js} +2 -2
- package/dist/{chunk-JXLQRAW2.js → chunk-MZPKOZE4.js} +129 -17
- package/dist/{chunk-YUSC6R6V.js → chunk-TJXUCAST.js} +1 -1
- package/dist/index.cjs +268 -32
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +141 -18
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +1 -1
- package/dist/src/browser.js +1 -1
- package/dist/src/connectors/base.d.ts +579 -59
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/react/index.cjs +2 -2
- package/dist/src/react/index.js +2 -2
- package/dist/src/server/index.cjs +128 -17
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +1 -3
- package/dist/src/server/mcp-server.d.ts +66 -4
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types.d.ts +39 -7
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -1
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -20
package/README.md
CHANGED
@@ -27,9 +27,18 @@
|
|
27
27
|
<img src="https://dcbadge.limes.pink/api/server/XkNkSkMz3V?style=flat" /></a>
|
28
28
|
</p>
|
29
29
|
|
30
|
-
🌐 **MCP
|
30
|
+
🌐 **MCP-Use** is a complete TypeScript framework for building and using MCP (Model Context Protocol) applications. It provides both a powerful **client library** for connecting LLMs to MCP servers and a **server framework** for building your own MCP servers with UI capabilities.
|
31
31
|
|
32
|
-
💡
|
32
|
+
💡 Build custom AI agents, create MCP servers with React UI widgets, and debug everything with the built-in inspector - all in TypeScript.
|
33
|
+
|
34
|
+
## 📦 MCP-Use Ecosystem
|
35
|
+
|
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-ts/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-ts/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-ts/tree/main/packages/create-mcp-use-app) | Create MCP apps with one command | [](https://www.npmjs.com/package/create-mcp-use-app) |
|
33
42
|
|
34
43
|
---
|
35
44
|
|
@@ -455,6 +464,185 @@ const agent = new MCPAgent({
|
|
455
464
|
})
|
456
465
|
```
|
457
466
|
|
467
|
+
---
|
468
|
+
|
469
|
+
## 🖥️ MCP Server Framework
|
470
|
+
|
471
|
+
Beyond being a powerful MCP client, mcp-use also provides a complete server framework for building your own MCP servers with built-in UI capabilities and automatic inspector integration.
|
472
|
+
|
473
|
+
### Quick Server Setup
|
474
|
+
|
475
|
+
```ts
|
476
|
+
import { createMCPServer } from 'mcp-use/server'
|
477
|
+
|
478
|
+
// Create your MCP server
|
479
|
+
const server = createMCPServer('my-awesome-server', {
|
480
|
+
version: '1.0.0',
|
481
|
+
description: 'My MCP server with tools, resources, and prompts'
|
482
|
+
})
|
483
|
+
|
484
|
+
// Define tools
|
485
|
+
server.tool('search_web', {
|
486
|
+
description: 'Search the web for information',
|
487
|
+
parameters: z.object({
|
488
|
+
query: z.string().describe('Search query')
|
489
|
+
}),
|
490
|
+
execute: async (args) => {
|
491
|
+
// Your tool implementation
|
492
|
+
return { results: await performSearch(args.query) }
|
493
|
+
}
|
494
|
+
})
|
495
|
+
|
496
|
+
// Define resources
|
497
|
+
server.resource('config', {
|
498
|
+
description: 'Application configuration',
|
499
|
+
uri: 'config://settings',
|
500
|
+
mimeType: 'application/json',
|
501
|
+
fetch: async () => {
|
502
|
+
return JSON.stringify(await getConfig(), null, 2)
|
503
|
+
}
|
504
|
+
})
|
505
|
+
|
506
|
+
// Define prompts
|
507
|
+
server.prompt('code_review', {
|
508
|
+
description: 'Review code for best practices',
|
509
|
+
arguments: [
|
510
|
+
{ name: 'code', description: 'Code to review', required: true }
|
511
|
+
],
|
512
|
+
render: async (args) => {
|
513
|
+
return `Please review this code:\n\n${args.code}`
|
514
|
+
}
|
515
|
+
})
|
516
|
+
|
517
|
+
// Start the server
|
518
|
+
server.listen(3000)
|
519
|
+
// 🎉 Inspector automatically available at http://localhost:3000/inspector
|
520
|
+
// 🚀 MCP endpoint available at http://localhost:3000/mcp
|
521
|
+
```
|
522
|
+
|
523
|
+
### Key Server Features
|
524
|
+
|
525
|
+
| Feature | Description |
|
526
|
+
|---------|-------------|
|
527
|
+
| **🔍 Auto Inspector** | Inspector UI automatically mounts at `/inspector` for debugging |
|
528
|
+
| **🎨 UI Widgets** | Build custom React UI components served alongside your MCP tools |
|
529
|
+
| **🔐 OAuth Support** | Built-in OAuth flow handling for secure authentication |
|
530
|
+
| **📡 Multiple Transports** | HTTP/SSE and WebSocket support out of the box |
|
531
|
+
| **🛠️ TypeScript First** | Full TypeScript support with type inference |
|
532
|
+
| **♻️ Hot Reload** | Development mode with automatic reloading |
|
533
|
+
| **📊 Observability** | Built-in logging and monitoring capabilities |
|
534
|
+
|
535
|
+
### Building UI Widgets
|
536
|
+
|
537
|
+
MCP-Use supports building custom UI widgets for your MCP tools using React:
|
538
|
+
|
539
|
+
```tsx
|
540
|
+
// resources/task-manager.tsx
|
541
|
+
import React, { useState } from 'react'
|
542
|
+
import { useMcp } from 'mcp-use/react'
|
543
|
+
|
544
|
+
export default function TaskManager() {
|
545
|
+
const { callTool } = useMcp()
|
546
|
+
const [tasks, setTasks] = useState<Task[]>([])
|
547
|
+
|
548
|
+
const addTask = async (title: string) => {
|
549
|
+
const result = await callTool('create_task', { title })
|
550
|
+
setTasks([...tasks, result])
|
551
|
+
}
|
552
|
+
|
553
|
+
return (
|
554
|
+
<div>
|
555
|
+
<h1>Task Manager</h1>
|
556
|
+
{/* Your UI implementation */}
|
557
|
+
</div>
|
558
|
+
)
|
559
|
+
}
|
560
|
+
```
|
561
|
+
|
562
|
+
Build and serve widgets using the MCP-Use CLI:
|
563
|
+
|
564
|
+
```bash
|
565
|
+
# Development with hot reload and auto-open inspector
|
566
|
+
npx @mcp-use/cli dev
|
567
|
+
|
568
|
+
# Production build
|
569
|
+
npx @mcp-use/cli build
|
570
|
+
|
571
|
+
# Start production server
|
572
|
+
npx @mcp-use/cli start
|
573
|
+
```
|
574
|
+
|
575
|
+
### Advanced Server Configuration
|
576
|
+
|
577
|
+
```ts
|
578
|
+
const server = createMCPServer('advanced-server', {
|
579
|
+
version: '1.0.0',
|
580
|
+
description: 'Advanced MCP server with custom configuration',
|
581
|
+
// Custom inspector path (default: /inspector)
|
582
|
+
inspectorPath: '/debug',
|
583
|
+
// Custom MCP endpoint (default: /mcp)
|
584
|
+
mcpPath: '/api/mcp',
|
585
|
+
// Enable CORS for browser access
|
586
|
+
cors: {
|
587
|
+
origin: ['http://localhost:3000', 'https://myapp.com'],
|
588
|
+
credentials: true
|
589
|
+
},
|
590
|
+
// OAuth configuration
|
591
|
+
oauth: {
|
592
|
+
clientId: process.env.OAUTH_CLIENT_ID,
|
593
|
+
clientSecret: process.env.OAUTH_CLIENT_SECRET,
|
594
|
+
authorizationUrl: 'https://api.example.com/oauth/authorize',
|
595
|
+
tokenUrl: 'https://api.example.com/oauth/token',
|
596
|
+
scopes: ['read', 'write']
|
597
|
+
},
|
598
|
+
// Custom middleware
|
599
|
+
middleware: [
|
600
|
+
authenticationMiddleware,
|
601
|
+
rateLimitingMiddleware
|
602
|
+
]
|
603
|
+
})
|
604
|
+
```
|
605
|
+
|
606
|
+
### Server Deployment
|
607
|
+
|
608
|
+
Deploy your MCP server to any Node.js hosting platform:
|
609
|
+
|
610
|
+
```bash
|
611
|
+
# Build for production
|
612
|
+
npm run build
|
613
|
+
|
614
|
+
# Start with PM2
|
615
|
+
pm2 start dist/index.js --name mcp-server
|
616
|
+
|
617
|
+
# Docker deployment
|
618
|
+
docker build -t my-mcp-server .
|
619
|
+
docker run -p 3000:3000 my-mcp-server
|
620
|
+
```
|
621
|
+
|
622
|
+
### Integration with Express
|
623
|
+
|
624
|
+
You can also integrate MCP server into existing Express applications:
|
625
|
+
|
626
|
+
```ts
|
627
|
+
import express from 'express'
|
628
|
+
import { mountMCPServer } from 'mcp-use/server'
|
629
|
+
|
630
|
+
const app = express()
|
631
|
+
|
632
|
+
// Your existing routes
|
633
|
+
app.get('/api/health', (req, res) => res.send('OK'))
|
634
|
+
|
635
|
+
// Mount MCP server
|
636
|
+
const mcpServer = createMCPServer('integrated-server', { /* ... */ })
|
637
|
+
mountMCPServer(app, mcpServer, {
|
638
|
+
basePath: '/mcp-service' // Optional custom base path
|
639
|
+
})
|
640
|
+
|
641
|
+
app.listen(3000)
|
642
|
+
// Inspector at: http://localhost:3000/mcp-service/inspector
|
643
|
+
// MCP endpoint: http://localhost:3000/mcp-service/mcp
|
644
|
+
```
|
645
|
+
|
458
646
|
## 👥 Contributors
|
459
647
|
|
460
648
|
<table>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import {
|
2
2
|
BrowserOAuthClientProvider
|
3
|
-
} from "./chunk-
|
3
|
+
} from "./chunk-TJXUCAST.js";
|
4
4
|
import {
|
5
5
|
__name
|
6
6
|
} from "./chunk-SHUYVCID.js";
|
@@ -160,7 +160,7 @@ function useMcp(options) {
|
|
160
160
|
}
|
161
161
|
if (!clientRef.current) {
|
162
162
|
clientRef.current = new Client(
|
163
|
-
{ name: clientConfig.name || "
|
163
|
+
{ name: clientConfig.name || "mcp-use", version: clientConfig.version || "0.1.0" },
|
164
164
|
{ capabilities: {} }
|
165
165
|
);
|
166
166
|
addLog("debug", "MCP Client initialized in connect.");
|
@@ -3,7 +3,7 @@ import {
|
|
3
3
|
} from "./chunk-SHUYVCID.js";
|
4
4
|
|
5
5
|
// src/server/mcp-server.ts
|
6
|
-
import { McpServer as OfficialMcpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
6
|
+
import { McpServer as OfficialMcpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
7
7
|
import { z } from "zod";
|
8
8
|
import express from "express";
|
9
9
|
import { existsSync, readdirSync } from "fs";
|
@@ -67,6 +67,7 @@ var McpServer = class {
|
|
67
67
|
version: config.version
|
68
68
|
});
|
69
69
|
this.app = express();
|
70
|
+
this.app.use(express.json());
|
70
71
|
this.app.use((req, res, next) => {
|
71
72
|
res.header("Access-Control-Allow-Origin", "*");
|
72
73
|
res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
|
@@ -95,7 +96,10 @@ var McpServer = class {
|
|
95
96
|
* @param resourceDefinition - Configuration object containing resource metadata and handler function
|
96
97
|
* @param resourceDefinition.name - Unique identifier for the resource
|
97
98
|
* @param resourceDefinition.uri - URI pattern for accessing the resource
|
98
|
-
* @param resourceDefinition.
|
99
|
+
* @param resourceDefinition.title - Optional human-readable title for the resource
|
100
|
+
* @param resourceDefinition.description - Optional description of the resource
|
101
|
+
* @param resourceDefinition.mimeType - MIME type of the resource content
|
102
|
+
* @param resourceDefinition.annotations - Optional annotations (audience, priority, lastModified)
|
99
103
|
* @param resourceDefinition.fn - Async function that returns the resource content
|
100
104
|
* @returns The server instance for method chaining
|
101
105
|
*
|
@@ -104,8 +108,20 @@ var McpServer = class {
|
|
104
108
|
* server.resource({
|
105
109
|
* name: 'config',
|
106
110
|
* uri: 'config://app-settings',
|
107
|
-
*
|
108
|
-
*
|
111
|
+
* title: 'Application Settings',
|
112
|
+
* mimeType: 'application/json',
|
113
|
+
* description: 'Current application configuration',
|
114
|
+
* annotations: {
|
115
|
+
* audience: ['user'],
|
116
|
+
* priority: 0.8
|
117
|
+
* },
|
118
|
+
* fn: async () => ({
|
119
|
+
* contents: [{
|
120
|
+
* uri: 'config://app-settings',
|
121
|
+
* mimeType: 'application/json',
|
122
|
+
* text: JSON.stringify({ theme: 'dark', language: 'en' })
|
123
|
+
* }]
|
124
|
+
* })
|
109
125
|
* })
|
110
126
|
* ```
|
111
127
|
*/
|
@@ -113,7 +129,13 @@ var McpServer = class {
|
|
113
129
|
this.server.resource(
|
114
130
|
resourceDefinition.name,
|
115
131
|
resourceDefinition.uri,
|
116
|
-
|
132
|
+
{
|
133
|
+
name: resourceDefinition.name,
|
134
|
+
title: resourceDefinition.title,
|
135
|
+
description: resourceDefinition.description,
|
136
|
+
mimeType: resourceDefinition.mimeType,
|
137
|
+
annotations: resourceDefinition.annotations
|
138
|
+
},
|
117
139
|
async () => {
|
118
140
|
return await resourceDefinition.fn();
|
119
141
|
}
|
@@ -122,18 +144,76 @@ var McpServer = class {
|
|
122
144
|
}
|
123
145
|
/**
|
124
146
|
* Define a dynamic resource template with parameters
|
147
|
+
*
|
148
|
+
* Registers a parameterized resource template with the MCP server. Templates use URI
|
149
|
+
* patterns with placeholders that can be filled in at request time, allowing dynamic
|
150
|
+
* resource generation based on parameters.
|
151
|
+
*
|
152
|
+
* @param resourceTemplateDefinition - Configuration object for the resource template
|
153
|
+
* @param resourceTemplateDefinition.name - Unique identifier for the template
|
154
|
+
* @param resourceTemplateDefinition.resourceTemplate - ResourceTemplate object with uriTemplate and metadata
|
155
|
+
* @param resourceTemplateDefinition.fn - Async function that generates resource content from URI and params
|
156
|
+
* @returns The server instance for method chaining
|
157
|
+
*
|
158
|
+
* @example
|
159
|
+
* ```typescript
|
160
|
+
* server.resourceTemplate({
|
161
|
+
* name: 'user-profile',
|
162
|
+
* resourceTemplate: {
|
163
|
+
* uriTemplate: 'user://{userId}/profile',
|
164
|
+
* name: 'User Profile',
|
165
|
+
* mimeType: 'application/json'
|
166
|
+
* },
|
167
|
+
* fn: async (uri, params) => ({
|
168
|
+
* contents: [{
|
169
|
+
* uri: uri.toString(),
|
170
|
+
* mimeType: 'application/json',
|
171
|
+
* text: JSON.stringify({ userId: params.userId, name: 'John Doe' })
|
172
|
+
* }]
|
173
|
+
* })
|
174
|
+
* })
|
175
|
+
* ```
|
125
176
|
*/
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
177
|
+
resourceTemplate(resourceTemplateDefinition) {
|
178
|
+
const template = new ResourceTemplate(
|
179
|
+
resourceTemplateDefinition.resourceTemplate.uriTemplate,
|
180
|
+
{
|
181
|
+
list: void 0,
|
182
|
+
// Optional: callback to list all matching resources
|
183
|
+
complete: void 0
|
184
|
+
// Optional: callback for auto-completion
|
185
|
+
}
|
186
|
+
);
|
187
|
+
const metadata = {};
|
188
|
+
if (resourceTemplateDefinition.resourceTemplate.name) {
|
189
|
+
metadata.name = resourceTemplateDefinition.resourceTemplate.name;
|
190
|
+
}
|
191
|
+
if (resourceTemplateDefinition.title) {
|
192
|
+
metadata.title = resourceTemplateDefinition.title;
|
193
|
+
}
|
194
|
+
if (resourceTemplateDefinition.description || resourceTemplateDefinition.resourceTemplate.description) {
|
195
|
+
metadata.description = resourceTemplateDefinition.description || resourceTemplateDefinition.resourceTemplate.description;
|
196
|
+
}
|
197
|
+
if (resourceTemplateDefinition.resourceTemplate.mimeType) {
|
198
|
+
metadata.mimeType = resourceTemplateDefinition.resourceTemplate.mimeType;
|
199
|
+
}
|
200
|
+
if (resourceTemplateDefinition.annotations) {
|
201
|
+
metadata.annotations = resourceTemplateDefinition.annotations;
|
202
|
+
}
|
203
|
+
this.server.resource(
|
204
|
+
resourceTemplateDefinition.name,
|
205
|
+
template,
|
206
|
+
metadata,
|
207
|
+
async (uri) => {
|
208
|
+
const params = this.parseTemplateUri(
|
209
|
+
resourceTemplateDefinition.resourceTemplate.uriTemplate,
|
210
|
+
uri.toString()
|
211
|
+
);
|
212
|
+
return await resourceTemplateDefinition.fn(uri, params);
|
213
|
+
}
|
214
|
+
);
|
215
|
+
return this;
|
216
|
+
}
|
137
217
|
/**
|
138
218
|
* Define a tool that can be called by clients
|
139
219
|
*
|
@@ -515,6 +595,39 @@ var McpServer = class {
|
|
515
595
|
const matches = uriTemplate.match(/\{([^}]+)\}/g);
|
516
596
|
return matches ? matches.map((match) => match.slice(1, -1)) : [];
|
517
597
|
}
|
598
|
+
/**
|
599
|
+
* Parse parameter values from a URI based on a template
|
600
|
+
*
|
601
|
+
* Extracts parameter values from an actual URI by matching it against a URI template.
|
602
|
+
* The template contains placeholders like {param} which are extracted as key-value pairs.
|
603
|
+
*
|
604
|
+
* @param template - URI template with placeholders (e.g., "user://{userId}/posts/{postId}")
|
605
|
+
* @param uri - Actual URI to parse (e.g., "user://123/posts/456")
|
606
|
+
* @returns Object mapping parameter names to their values
|
607
|
+
*
|
608
|
+
* @example
|
609
|
+
* ```typescript
|
610
|
+
* const params = this.parseTemplateUri("user://{userId}/posts/{postId}", "user://123/posts/456")
|
611
|
+
* // Returns: { userId: "123", postId: "456" }
|
612
|
+
* ```
|
613
|
+
*/
|
614
|
+
parseTemplateUri(template, uri) {
|
615
|
+
const params = {};
|
616
|
+
let regexPattern = template.replace(/[.*+?^$()[\]\\|]/g, "\\$&");
|
617
|
+
const paramNames = [];
|
618
|
+
regexPattern = regexPattern.replace(/\\\{([^}]+)\\\}/g, (_, paramName) => {
|
619
|
+
paramNames.push(paramName);
|
620
|
+
return "([^/]+)";
|
621
|
+
});
|
622
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
623
|
+
const match = uri.match(regex);
|
624
|
+
if (match) {
|
625
|
+
paramNames.forEach((paramName, index) => {
|
626
|
+
params[paramName] = match[index + 1];
|
627
|
+
});
|
628
|
+
}
|
629
|
+
return params;
|
630
|
+
}
|
518
631
|
};
|
519
632
|
function createMCPServer(name, config = {}) {
|
520
633
|
const instance = new McpServer({
|
@@ -527,6 +640,5 @@ function createMCPServer(name, config = {}) {
|
|
527
640
|
__name(createMCPServer, "createMCPServer");
|
528
641
|
|
529
642
|
export {
|
530
|
-
McpServer,
|
531
643
|
createMCPServer
|
532
644
|
};
|
@@ -20,7 +20,7 @@ var BrowserOAuthClientProvider = class {
|
|
20
20
|
this.serverUrl = serverUrl;
|
21
21
|
this.storageKeyPrefix = options.storageKeyPrefix || "mcp:auth";
|
22
22
|
this.serverUrlHash = this.hashString(serverUrl);
|
23
|
-
this.clientName = options.clientName || "
|
23
|
+
this.clientName = options.clientName || "mcp-use";
|
24
24
|
this.clientUri = options.clientUri || (typeof window !== "undefined" ? window.location.origin : "");
|
25
25
|
this.callbackUrl = sanitizeUrl(
|
26
26
|
options.callbackUrl || (typeof window !== "undefined" ? new URL("/oauth/callback", window.location.origin).toString() : "/oauth/callback")
|