@mastra/mcp 1.6.0 → 1.6.1-alpha.0
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/CHANGELOG.md +9 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +1 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-tools-mcp-server.md +1 -3
- package/dist/index.cjs +58 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -2
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/docs/references/docs-mcp-publishing-mcp-server.md +0 -115
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "1.6.0",
|
|
3
|
+
"version": "1.6.1-alpha.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -40,22 +40,22 @@
|
|
|
40
40
|
"@types/node": "22.19.15",
|
|
41
41
|
"@vitest/coverage-v8": "4.1.5",
|
|
42
42
|
"@vitest/ui": "4.1.5",
|
|
43
|
-
"ai": "^5.0.
|
|
43
|
+
"ai": "^5.0.179",
|
|
44
44
|
"eslint": "^10.2.1",
|
|
45
45
|
"hono": "^4.12.8",
|
|
46
46
|
"hono-mcp-server-sse-transport": "0.0.7",
|
|
47
47
|
"tsup": "^8.5.1",
|
|
48
48
|
"tsx": "^4.21.0",
|
|
49
|
-
"typescript": "^
|
|
49
|
+
"typescript": "^6.0.3",
|
|
50
50
|
"vitest": "4.1.5",
|
|
51
51
|
"zod": "^4.3.6",
|
|
52
52
|
"zod-to-json-schema": "^3.25.1",
|
|
53
|
-
"@internal/
|
|
54
|
-
"@internal/
|
|
55
|
-
"@internal/types-builder": "0.0.
|
|
56
|
-
"@mastra/core": "1.
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
53
|
+
"@internal/test-utils": "0.0.26",
|
|
54
|
+
"@internal/lint": "0.0.90",
|
|
55
|
+
"@internal/types-builder": "0.0.65",
|
|
56
|
+
"@mastra/core": "1.31.1-alpha.0",
|
|
57
|
+
"@internal/llm-recorder": "0.0.26",
|
|
58
|
+
"@mastra/schema-compat": "1.2.9"
|
|
59
59
|
},
|
|
60
60
|
"homepage": "https://mastra.ai",
|
|
61
61
|
"repository": {
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
# Publishing an MCP server
|
|
2
|
-
|
|
3
|
-
This example guides you through setting up a basic Mastra MCPServer using the stdio transport, building it, and preparing it for publishing to NPM.
|
|
4
|
-
|
|
5
|
-
## Install dependencies
|
|
6
|
-
|
|
7
|
-
Install the necessary packages:
|
|
8
|
-
|
|
9
|
-
**npm**:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @mastra/mcp @mastra/core tsup
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
**pnpm**:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
pnpm add @mastra/mcp @mastra/core tsup
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
**Yarn**:
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
yarn add @mastra/mcp @mastra/core tsup
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**Bun**:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
bun add @mastra/mcp @mastra/core tsup
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Setting up an MCP server
|
|
34
|
-
|
|
35
|
-
1. Create a file for your stdio server, for example, `/src/mastra/stdio.ts`.
|
|
36
|
-
|
|
37
|
-
2. Add the following code to the file. Remember to import your actual Mastra tools and name the server appropriately.
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
#!/usr/bin/env node
|
|
41
|
-
import { MCPServer } from '@mastra/mcp'
|
|
42
|
-
import { weatherTool } from './tools'
|
|
43
|
-
|
|
44
|
-
const server = new MCPServer({
|
|
45
|
-
name: 'my-mcp-server',
|
|
46
|
-
version: '1.0.0',
|
|
47
|
-
tools: { weatherTool },
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
server.startStdio().catch(error => {
|
|
51
|
-
console.error('Error running MCP server:', error)
|
|
52
|
-
process.exit(1)
|
|
53
|
-
})
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
3. Update your `package.json` to include the `bin` entry pointing to your built server file and a script to build the server with both ESM and CJS outputs.
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
{
|
|
60
|
-
"bin": "dist/stdio.mjs",
|
|
61
|
-
"scripts": {
|
|
62
|
-
"build:mcp": "tsup src/mastra/stdio.ts --format esm,cjs --no-splitting --dts && echo '#!/usr/bin/env node' | cat - dist/stdio.mjs > temp && mv temp dist/stdio.mjs && chmod +x dist/stdio.mjs"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
The build command generates both ESM (`.mjs`) and CJS (`.cjs`) outputs for maximum compatibility. The shebang (`#!/usr/bin/env node`) is prepended to the ESM artifact to make it directly executable, and the `bin` entry points to this file.
|
|
68
|
-
|
|
69
|
-
4. Run the build command:
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
pnpm run build:mcp
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
This will compile your server code into both ESM and CJS formats and make the ESM output file executable. On Unix-like systems, the `chmod +x` step makes the file directly executable. Windows users may need to use WSL or handle execution through Node.js directly.
|
|
76
|
-
|
|
77
|
-
## Publishing to NPM
|
|
78
|
-
|
|
79
|
-
To make your MCP server available for others (or yourself) to use via `npx` or as a dependency, you can publish it to NPM.
|
|
80
|
-
|
|
81
|
-
1. Ensure you have an NPM account and are logged in (`npm login`).
|
|
82
|
-
|
|
83
|
-
2. Make sure your package name in `package.json` is unique and available.
|
|
84
|
-
|
|
85
|
-
3. Run the publish command from your project root after building:
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
npm publish --access public
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
For more details on publishing packages, refer to the [NPM documentation](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages).
|
|
92
|
-
|
|
93
|
-
## Using a published MCP server
|
|
94
|
-
|
|
95
|
-
Once published, your MCP server can be used by an `MCPClient` by specifying the command to run your package. You can also use any other MCP client like Claude desktop, Cursor, or Windsurf.
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
import { MCPClient } from '@mastra/mcp'
|
|
99
|
-
|
|
100
|
-
const mcp = new MCPClient({
|
|
101
|
-
servers: {
|
|
102
|
-
// Give this MCP server instance a name
|
|
103
|
-
yourServerName: {
|
|
104
|
-
command: 'npx',
|
|
105
|
-
args: ['-y', '@your-org-name/your-package-name@latest'], // Replace with your package name
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
// You can then get tools or toolsets from this configuration to use in your agent
|
|
111
|
-
const tools = await mcp.listTools()
|
|
112
|
-
const toolsets = await mcp.listToolsets()
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Note: If you published without an organization scope, the `args` might be `["-y", "your-package-name@latest"]`.
|