@mastra/mcp 1.16.0 → 1.17.0-alpha.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.
- package/CHANGELOG.md +49 -0
- package/dist/client/configuration.d.ts +11 -3
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/docs/SKILL.md +4 -4
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/{docs-server-auth-fga.md → docs-auth-fga.md} +1 -1
- package/dist/docs/references/{docs-mcp-overview.md → docs-connections-mcp.md} +6 -7
- package/dist/docs/references/docs-connections-overview.md +6 -6
- package/dist/docs/references/reference-editor-tools.md +2 -2
- package/dist/docs/references/reference-migrations-upgrade-to-v1-mcp.md +1 -1
- package/dist/docs/references/reference-tools-mcp-client.md +37 -8
- package/dist/docs/references/reference-tools-mcp-server.md +55 -7
- package/dist/index.cjs +59 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -17
- package/dist/index.js.map +1 -1
- package/dist/server/server.d.ts +3 -1
- package/dist/server/server.d.ts.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @mastra/mcp
|
|
2
2
|
|
|
3
|
+
## 1.17.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- MCP tools served over HTTP now see the authenticated caller. When an MCP server runs behind a Mastra server with `server.auth` configured, the resolved user is bridged into `extra.authInfo` automatically, on both the streamable HTTP and SSE transports. Previously `extra.authInfo` was always undefined because the request handed to the MCP transport was rebuilt without the auth data. ([#21689](https://github.com/mastra-ai/mastra/pull/21689))
|
|
8
|
+
|
|
9
|
+
**Custom verification**
|
|
10
|
+
|
|
11
|
+
If your own middleware verifies the caller, build the auth info yourself with the new `server.mcpOptions.setRequestAuth` hook:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
export const mastra = new Mastra({
|
|
15
|
+
mcpServers: { myServer },
|
|
16
|
+
server: {
|
|
17
|
+
middleware: [verifyBearerToken],
|
|
18
|
+
mcpOptions: {
|
|
19
|
+
setRequestAuth: (req, requestContext) => {
|
|
20
|
+
const payload = requestContext.get('bearerPayload');
|
|
21
|
+
req.auth = { token: payload.token, clientId: payload.sub, scopes: payload.scope.split(' ') };
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Fixes #17291
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies [[`4e7a421`](https://github.com/mastra-ai/mastra/commit/4e7a421dce8a48742f785d1e93ad2f43a572b282), [`242e324`](https://github.com/mastra-ai/mastra/commit/242e3241e73cbd5c9bb86a31ebb49ca0256488d4), [`217e967`](https://github.com/mastra-ai/mastra/commit/217e9672d8b3160eb729d8e9f0044949e88da239), [`d774e89`](https://github.com/mastra-ai/mastra/commit/d774e8930c781df8c9effe3763e6b501c099b6cc), [`9c27a53`](https://github.com/mastra-ai/mastra/commit/9c27a53cd9d3de4f3f025bc387d94ce371c33f95), [`dff25a1`](https://github.com/mastra-ai/mastra/commit/dff25a1103fa72ee082a9b6f805ebeb5ce400753), [`217e967`](https://github.com/mastra-ai/mastra/commit/217e9672d8b3160eb729d8e9f0044949e88da239), [`7f78585`](https://github.com/mastra-ai/mastra/commit/7f785857e401570e2ffb316911f126ed363aa537), [`f2a4afd`](https://github.com/mastra-ai/mastra/commit/f2a4afd7e37e809669001ed17724b341a5c1f45e), [`d438148`](https://github.com/mastra-ai/mastra/commit/d438148e222c1e2fb3c652725ce75680962ebec4), [`ba05fe0`](https://github.com/mastra-ai/mastra/commit/ba05fe0738f70cb686777546e968237d09269142), [`d26a8d4`](https://github.com/mastra-ai/mastra/commit/d26a8d4281f28414715b333c85bedaf70d0b2890), [`677cdc6`](https://github.com/mastra-ai/mastra/commit/677cdc6af564dec29a13464d12b7ab2a4efc22e9), [`a318490`](https://github.com/mastra-ai/mastra/commit/a318490e17da32f338d50929c770d901a9b3dd72), [`763e0c6`](https://github.com/mastra-ai/mastra/commit/763e0c61e04d76ad9a9efd301aa57525ca0cbea9), [`23e0be2`](https://github.com/mastra-ai/mastra/commit/23e0be261381e49534b4ff3101c60ee64a946cbf), [`7fc8806`](https://github.com/mastra-ai/mastra/commit/7fc880627d3cbf995d31ea0e8b807bf15417e651), [`0e02eac`](https://github.com/mastra-ai/mastra/commit/0e02eacdb2e30e1697a41910b41163742a181dc1), [`4df174c`](https://github.com/mastra-ai/mastra/commit/4df174c32bddf093a82f273070b8380aef7c9e90), [`f7c25b5`](https://github.com/mastra-ai/mastra/commit/f7c25b5106ddfb48e591f98df7a51e0f2dd01dba), [`dc09cc1`](https://github.com/mastra-ai/mastra/commit/dc09cc1083d861cde192c1cd235324dc75b8c731), [`36b4649`](https://github.com/mastra-ai/mastra/commit/36b4649045a3a380cbab8ceca866db4086223aff), [`377eb81`](https://github.com/mastra-ai/mastra/commit/377eb81ce43b964e3a6b541df172da74a8ff3716)]:
|
|
33
|
+
- @mastra/core@1.60.0-alpha.8
|
|
34
|
+
|
|
35
|
+
## 1.17.0-alpha.0
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- Added per-server time budgets and duration metrics to MCP discovery methods. ([#21560](https://github.com/mastra-ai/mastra/pull/21560))
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const { tools, errors, durations } = await mcp.listToolsWithErrors({
|
|
43
|
+
perServerTimeoutMs: 3_000,
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`d7e6745`](https://github.com/mastra-ai/mastra/commit/d7e67456954863c55440ea9c49bc6ceb9949972d), [`9acb50f`](https://github.com/mastra-ai/mastra/commit/9acb50f71cec9c362f06820033f90ae6b1f8282f), [`46e9e3f`](https://github.com/mastra-ai/mastra/commit/46e9e3f73babe1bc70080a596cf2ac0b9da48519), [`3f9a190`](https://github.com/mastra-ai/mastra/commit/3f9a19057c027155867b9317294ee4ca7bd0581a), [`e8808e3`](https://github.com/mastra-ai/mastra/commit/e8808e3d8eb585a2565be53e56a7e0e1477352a4), [`d4be8c1`](https://github.com/mastra-ai/mastra/commit/d4be8c1739d22d621e3f78790e1dd5eb5ecc3589), [`a5d2eb1`](https://github.com/mastra-ai/mastra/commit/a5d2eb10347eade1ae2816d88f466c25186c54a5), [`e81744c`](https://github.com/mastra-ai/mastra/commit/e81744cd13c46619c142dc521dc0baac47607a84)]:
|
|
50
|
+
- @mastra/core@1.60.0-alpha.4
|
|
51
|
+
|
|
3
52
|
## 1.16.0
|
|
4
53
|
|
|
5
54
|
### Minor Changes
|
|
@@ -5,6 +5,11 @@ import type { Tool } from '@mastra/core/tools';
|
|
|
5
5
|
import type { ElicitRequest, ElicitResult, ProgressNotification, Prompt, Resource, ResourceTemplateType } from '@modelcontextprotocol/client';
|
|
6
6
|
import type { MastraMCPServerDefinition, MCPServerAuthState } from './client.js';
|
|
7
7
|
import type { SerializableMCPToolCatalog, SerializableMCPToolDefinition } from './types.js';
|
|
8
|
+
/** Options for aggregate discovery across configured MCP servers. */
|
|
9
|
+
export interface MCPDiscoveryOptions {
|
|
10
|
+
/** Maximum time to wait for each server's discovery operation, in milliseconds. */
|
|
11
|
+
perServerTimeoutMs?: number;
|
|
12
|
+
}
|
|
8
13
|
/**
|
|
9
14
|
* Configuration options for creating an MCPClient instance.
|
|
10
15
|
*/
|
|
@@ -719,9 +724,10 @@ export declare class MCPClient extends MastraBase {
|
|
|
719
724
|
* }
|
|
720
725
|
* ```
|
|
721
726
|
*/
|
|
722
|
-
listToolsWithErrors(): Promise<{
|
|
727
|
+
listToolsWithErrors(options?: MCPDiscoveryOptions): Promise<{
|
|
723
728
|
tools: Record<string, Tool<any, any, any, any>>;
|
|
724
729
|
errors: Record<string, string>;
|
|
730
|
+
durations?: Record<string, number>;
|
|
725
731
|
}>;
|
|
726
732
|
/**
|
|
727
733
|
* Returns toolsets organized by server name for dynamic tool injection.
|
|
@@ -764,9 +770,10 @@ export declare class MCPClient extends MastraBase {
|
|
|
764
770
|
* }
|
|
765
771
|
* ```
|
|
766
772
|
*/
|
|
767
|
-
listToolsetsWithErrors(): Promise<{
|
|
773
|
+
listToolsetsWithErrors(options?: MCPDiscoveryOptions): Promise<{
|
|
768
774
|
toolsets: Record<string, Record<string, Tool<any, any, any, any>>>;
|
|
769
775
|
errors: Record<string, string>;
|
|
776
|
+
durations?: Record<string, number>;
|
|
770
777
|
}>;
|
|
771
778
|
/**
|
|
772
779
|
* Discovers every configured server's tools as plain, serializable definitions.
|
|
@@ -798,9 +805,10 @@ export declare class MCPClient extends MastraBase {
|
|
|
798
805
|
* Useful when caching a catalog, since it lets you avoid persisting a partial manifest that
|
|
799
806
|
* silently omits a server which happened to be down at discovery time.
|
|
800
807
|
*/
|
|
801
|
-
listToolDefinitionsWithErrors(): Promise<{
|
|
808
|
+
listToolDefinitionsWithErrors(options?: MCPDiscoveryOptions): Promise<{
|
|
802
809
|
definitions: SerializableMCPToolCatalog;
|
|
803
810
|
errors: Record<string, string>;
|
|
811
|
+
durations?: Record<string, number>;
|
|
804
812
|
}>;
|
|
805
813
|
/**
|
|
806
814
|
* Rebuilds an executable Mastra tool from a cached {@link SerializableMCPToolDefinition}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/client/configuration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EACV,aAAa,EACb,YA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YAIlB,iBAAiB;CAuBhC"}
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-mcp
|
|
|
3
3
|
description: Documentation for @mastra/mcp. Use when working with @mastra/mcp APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/mcp"
|
|
6
|
-
version: "1.
|
|
6
|
+
version: "1.17.0-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -16,9 +16,9 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
16
16
|
|
|
17
17
|
### Docs
|
|
18
18
|
|
|
19
|
-
- [
|
|
20
|
-
- [MCP
|
|
21
|
-
- [
|
|
19
|
+
- [Fine-Grained Authorization (FGA)](references/docs-auth-fga.md) - Add resource-level authorization to your Mastra application with FGA providers.
|
|
20
|
+
- [MCP](references/docs-connections-mcp.md) - Connect Mastra agents to external MCP servers and expose Mastra tools through MCPServer. You can also build interactive MCP Apps for Studio.
|
|
21
|
+
- [Connections](references/docs-connections-overview.md) - Connect Mastra to remote agents, coding agents, provider software development kit runtimes, and external tools and resources.
|
|
22
22
|
|
|
23
23
|
### Reference
|
|
24
24
|
|
|
@@ -299,5 +299,5 @@ The actor signal is trusted input, so construct it server-side:
|
|
|
299
299
|
## Related
|
|
300
300
|
|
|
301
301
|
- [`IFGAProvider` reference](https://mastra.ai/reference/auth/fga)
|
|
302
|
-
- [Authentication overview](https://mastra.ai/docs/
|
|
302
|
+
- [Authentication overview](https://mastra.ai/docs/auth/overview)
|
|
303
303
|
- [WorkOS authentication](https://mastra.ai/integrations/auth/workos)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# MCP
|
|
3
|
+
# MCP
|
|
4
4
|
|
|
5
5
|
Mastra supports the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction), an open standard for connecting AI agents to external tools and resources.
|
|
6
6
|
|
|
@@ -252,7 +252,7 @@ Use an MCP App when a tool result benefits from interaction, such as a form, cal
|
|
|
252
252
|
|
|
253
253
|
### Define an app resource
|
|
254
254
|
|
|
255
|
-
Return a short `content` summary for the model and place UI data in `structuredContent`. Link the tool to its app by setting `_meta.ui.resourceUri` to the same `ui://` URI used in `appResources`:
|
|
255
|
+
Return a short `content` summary for the model and place UI data in `structuredContent`. Link the tool to its app by setting `mcp._meta.ui.resourceUri` to the same `ui://` URI used in `appResources`:
|
|
256
256
|
|
|
257
257
|
```typescript
|
|
258
258
|
import { MCPServer } from '@mastra/mcp'
|
|
@@ -266,16 +266,15 @@ export const calculatorTool = createTool({
|
|
|
266
266
|
num1: z.number(),
|
|
267
267
|
num2: z.number(),
|
|
268
268
|
}),
|
|
269
|
+
mcp: {
|
|
270
|
+
_meta: { ui: { resourceUri: 'ui://calculator/main' } },
|
|
271
|
+
},
|
|
269
272
|
execute: async ({ num1, num2 }) => ({
|
|
270
273
|
content: [{ type: 'text', text: 'The result is displayed in the calculator app.' }],
|
|
271
274
|
structuredContent: { result: num1 + num2 },
|
|
272
275
|
}),
|
|
273
276
|
})
|
|
274
277
|
|
|
275
|
-
calculatorTool._meta = {
|
|
276
|
-
ui: { resourceUri: 'ui://calculator/main' },
|
|
277
|
-
}
|
|
278
|
-
|
|
279
278
|
export const calculatorMcpServer = new MCPServer({
|
|
280
279
|
id: 'calculator-app-server',
|
|
281
280
|
name: 'Calculator App Server',
|
|
@@ -407,7 +406,7 @@ App iframes allow scripts, forms, and popups. They can't access the parent page'
|
|
|
407
406
|
|
|
408
407
|
## Next steps
|
|
409
408
|
|
|
410
|
-
- [Use tools with agents](https://mastra.ai/docs/agents/
|
|
409
|
+
- [Use tools with agents](https://mastra.ai/docs/agents/tools)
|
|
411
410
|
- [`MCPClient` reference](https://mastra.ai/reference/tools/mcp-client)
|
|
412
411
|
- [`MCPServer` reference](https://mastra.ai/reference/tools/mcp-server)
|
|
413
412
|
- [MCP Apps extension specification](https://github.com/modelcontextprotocol/ext-apps)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# Connections
|
|
3
|
+
# Connections
|
|
4
4
|
|
|
5
5
|
Connections let Mastra work with remote agents, coding agents, provider software development kit (SDK) runtimes, and external tools and resources. Choose a connection type based on which system owns the agent runtime and what you need to exchange.
|
|
6
6
|
|
|
7
|
-
- [**
|
|
8
|
-
- [**Agent
|
|
9
|
-
- [**
|
|
10
|
-
- [**
|
|
7
|
+
- [**Model Context Protocol (MCP)**](https://mastra.ai/docs/connections/mcp): Connect agents to external tools and resources, or expose Mastra agents, tools, workflows, prompts, and resources to MCP-compatible systems.
|
|
8
|
+
- [**Agent-to-Agent (A2A)**](https://mastra.ai/docs/connections/a2a): Expose or consume remote agents across service, framework, vendor, and language boundaries.
|
|
9
|
+
- [**Agent Client Protocol (ACP)**](https://mastra.ai/docs/connections/acp): Run compatible coding-agent processes as Mastra tools or subagents.
|
|
10
|
+
- [**SDK agents**](https://mastra.ai/docs/connections/sdk-agents): Register Claude, Cursor, or OpenAI SDK-backed agents while the provider SDK retains control of the runtime, tools, permissions, and agent loop.
|
|
11
11
|
|
|
12
12
|
## When to use connections
|
|
13
13
|
|
|
@@ -20,7 +20,7 @@ Use connections when you need to:
|
|
|
20
20
|
|
|
21
21
|
## Get started
|
|
22
22
|
|
|
23
|
-
Start with the boundary you need to cross. Use [A2A](https://mastra.ai/docs/
|
|
23
|
+
Start with the boundary you need to cross. Use [A2A](https://mastra.ai/docs/connections/a2a) for remote agent endpoints, [ACP](https://mastra.ai/docs/connections/acp) for coding-agent processes, [SDK agents](https://mastra.ai/docs/connections/sdk-agents) for provider-owned runtimes, or [MCP](https://mastra.ai/docs/connections/mcp) for tools and resources.
|
|
24
24
|
|
|
25
25
|
**A2A**:
|
|
26
26
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# Tool configuration
|
|
4
4
|
|
|
5
|
-
Editor stores tool selections as part of an agent version. A stored configuration can add registered tools
|
|
5
|
+
Editor stores tool selections as part of an agent version. A stored configuration can add registered tools and tools from integration providers, as well as tools from Model Context Protocol (MCP) clients.
|
|
6
6
|
|
|
7
|
-
See [Editor tools](https://mastra.ai/docs/editor
|
|
7
|
+
See [Editor tools](https://mastra.ai/docs/studio/editor) for the Studio workflow and common uses.
|
|
8
8
|
|
|
9
9
|
## Tool sources
|
|
10
10
|
|
|
@@ -59,7 +59,7 @@ To migrate, replace all calls to `mcp.getToolsets()` with `mcp.listToolsets()`.
|
|
|
59
59
|
|
|
60
60
|
### MCP tool context properties organization
|
|
61
61
|
|
|
62
|
-
Context properties in MCP tools are now organized under the `context.mcp` namespace.
|
|
62
|
+
Context properties in MCP tools are now organized under the `context.mcp` namespace. The namespace organizes MCP-specific functionality under a clear API surface.
|
|
63
63
|
|
|
64
64
|
To migrate, access MCP-specific properties like `elicitation` and `extra` through `context.mcp` instead of directly from the context parameter.
|
|
65
65
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# MCPClient
|
|
4
4
|
|
|
5
|
-
The `MCPClient` class provides a way to manage multiple MCP server connections and their tools in a Mastra application. It handles connection lifecycle
|
|
5
|
+
The `MCPClient` class provides a way to manage multiple MCP server connections and their tools in a Mastra application. It handles connection lifecycle and tool namespacing while providing access to tools across all configured servers.
|
|
6
6
|
|
|
7
7
|
## Constructor
|
|
8
8
|
|
|
@@ -223,17 +223,23 @@ Retrieves all tools from all configured servers, with tool names namespaced by t
|
|
|
223
223
|
new Agent({ id: 'agent', tools: await mcp.listTools() })
|
|
224
224
|
```
|
|
225
225
|
|
|
226
|
-
### `listToolsWithErrors()`
|
|
226
|
+
### `listToolsWithErrors(options?)`
|
|
227
227
|
|
|
228
228
|
Retrieves all tools from all configured servers, with tool names namespaced by their server name. Also returns per-server errors for servers that failed to connect or list tools.
|
|
229
229
|
|
|
230
|
+
Set `perServerTimeoutMs` to limit how long discovery waits for each server. Servers that finish within the limit remain in `tools`. Timed-out servers appear in `errors`, and `durations` reports each server's discovery time in milliseconds.
|
|
231
|
+
|
|
230
232
|
```typescript
|
|
231
|
-
const { tools, errors } = await mcp.listToolsWithErrors(
|
|
233
|
+
const { tools, errors, durations } = await mcp.listToolsWithErrors({
|
|
234
|
+
perServerTimeoutMs: 3_000,
|
|
235
|
+
})
|
|
232
236
|
|
|
233
237
|
new Agent({ id: 'agent', tools })
|
|
234
|
-
console.log(errors)
|
|
238
|
+
console.log(errors, durations)
|
|
235
239
|
```
|
|
236
240
|
|
|
241
|
+
When called without options, the method returns only `tools` and `errors`.
|
|
242
|
+
|
|
237
243
|
### `listToolsets()`
|
|
238
244
|
|
|
239
245
|
Returns an object mapping namespaced tool names (in the format `serverName.toolName`) to their tool implementations. Intended to be passed at runtime into the generate or stream method.
|
|
@@ -244,11 +250,26 @@ const res = await agent.stream(prompt, {
|
|
|
244
250
|
})
|
|
245
251
|
```
|
|
246
252
|
|
|
253
|
+
### `listToolsetsWithErrors(options?)`
|
|
254
|
+
|
|
255
|
+
Returns toolsets grouped by server name, along with per-server discovery errors. Set `perServerTimeoutMs` to limit each server independently and include per-server `durations` in milliseconds.
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
const { toolsets, errors, durations } = await mcp.listToolsetsWithErrors({
|
|
259
|
+
perServerTimeoutMs: 3_000,
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
const res = await agent.stream(prompt, { toolsets })
|
|
263
|
+
console.log(errors, durations)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
When called without options, the method returns only `toolsets` and `errors`.
|
|
267
|
+
|
|
247
268
|
### `listToolDefinitions()`
|
|
248
269
|
|
|
249
270
|
Returns every server's tools as plain, serializable definitions, grouped by server name and keyed by the server's own tool name (without the `serverName_toolName` namespacing that `listTools()` applies).
|
|
250
271
|
|
|
251
|
-
Unlike `listTools()`, the result contains no functions or references to a live client, so it can be passed through `JSON.stringify` and cached in Redis
|
|
272
|
+
Unlike `listTools()`, the result contains no functions or references to a live client, so it can be passed through `JSON.stringify` and cached in Redis or a database, as well as a build artifact. Each definition holds the data from the MCP `tools/list` response (name, description, input schema, output schema, annotations, and `_meta`), plus the server name, version, and instructions captured at discovery time.
|
|
252
273
|
|
|
253
274
|
```typescript
|
|
254
275
|
const definitions = await mcp.listToolDefinitions()
|
|
@@ -256,18 +277,26 @@ const definitions = await mcp.listToolDefinitions()
|
|
|
256
277
|
await cache.set('mcp-tools', JSON.stringify(definitions))
|
|
257
278
|
```
|
|
258
279
|
|
|
259
|
-
### `listToolDefinitionsWithErrors()`
|
|
280
|
+
### `listToolDefinitionsWithErrors(options?)`
|
|
260
281
|
|
|
261
282
|
Like `listToolDefinitions()`, but also returns per-server errors for servers that failed to connect. Use this when caching a catalog, so you don't persist a partial manifest that omits a server that was down at discovery time.
|
|
262
283
|
|
|
284
|
+
Set `perServerTimeoutMs` to limit each server independently. When options are provided, `durations` reports each server's discovery time in milliseconds.
|
|
285
|
+
|
|
263
286
|
```typescript
|
|
264
|
-
const { definitions, errors } = await mcp.listToolDefinitionsWithErrors(
|
|
287
|
+
const { definitions, errors, durations } = await mcp.listToolDefinitionsWithErrors({
|
|
288
|
+
perServerTimeoutMs: 3_000,
|
|
289
|
+
})
|
|
265
290
|
|
|
266
291
|
if (Object.keys(errors).length === 0) {
|
|
267
292
|
await cache.set('mcp-tools', JSON.stringify(definitions))
|
|
268
293
|
}
|
|
294
|
+
|
|
295
|
+
console.log(durations)
|
|
269
296
|
```
|
|
270
297
|
|
|
298
|
+
When called without options, the method returns only `definitions` and `errors`.
|
|
299
|
+
|
|
271
300
|
### `toolFromDefinition()`
|
|
272
301
|
|
|
273
302
|
Rebuilds a single executable tool from a cached definition. No connection is opened here. The client connects lazily, the first time the tool is executed.
|
|
@@ -991,7 +1020,7 @@ try {
|
|
|
991
1020
|
|
|
992
1021
|
Concurrent `authenticate()` calls for the same server join the pending flow. Different servers authenticate independently. With valid stored tokens the call reconnects without opening a browser.
|
|
993
1022
|
|
|
994
|
-
Hosts that drive the flow themselves can capture the authorization code with the exported `createOAuthCallbackServer` helper, which binds a one-shot loopback server
|
|
1023
|
+
Hosts that drive the flow themselves can capture the authorization code with the exported `createOAuthCallbackServer` helper, which binds a one-shot loopback server and validates the OAuth `state` parameter before resolving with the code. It creates a plain HTTP server, so it's only for local loopback redirects. Web applications that use an HTTPS redirect URL must host their own callback endpoint and drive the provider directly rather than using this helper:
|
|
995
1024
|
|
|
996
1025
|
```typescript
|
|
997
1026
|
import { createOAuthCallbackServer, getCallbackUrlCandidates } from '@mastra/mcp'
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# MCPServer
|
|
4
4
|
|
|
5
|
-
The `MCPServer` class provides the functionality to expose your existing Mastra tools and Agents as a Model Context Protocol (MCP) server.
|
|
5
|
+
The `MCPServer` class provides the functionality to expose your existing Mastra tools and Agents as a Model Context Protocol (MCP) server. Any MCP client, such as Cursor, Windsurf, or Claude Desktop, can connect to these capabilities and make them available to an agent.
|
|
6
6
|
|
|
7
7
|
Note that if you only need to use your tools or agents directly within your Mastra application, you don't necessarily need to create an MCP server. This API is specifically for exposing your Mastra tools and agents to _external_ MCP clients.
|
|
8
8
|
|
|
@@ -95,7 +95,7 @@ The constructor accepts an `MCPServerConfig` object with the following propertie
|
|
|
95
95
|
|
|
96
96
|
A powerful feature of `MCPServer` is its ability to automatically expose your Mastra Agents as callable tools. When you provide agents in the `agents` property of the configuration:
|
|
97
97
|
|
|
98
|
-
- **Tool Naming**: Each agent is converted into a tool
|
|
98
|
+
- **Tool Naming**: Each agent is converted into a tool with the name `ask_<agentKey>`, where `<agentKey>` is the key you used for that agent in the `agents` object. For instance, if you configure `agents: { myAgentKey: myAgentInstance }`, a tool with the name `ask_myAgentKey` will be created.
|
|
99
99
|
|
|
100
100
|
- **Tool Functionality**:
|
|
101
101
|
|
|
@@ -104,7 +104,7 @@ A powerful feature of `MCPServer` is its ability to automatically expose your Ma
|
|
|
104
104
|
- **Execution**: When this tool is called, it invokes the corresponding agent's `generate()` method with the provided `query`.
|
|
105
105
|
- **Output**: The direct result from the agent's `generate()` method is returned as the output of the tool.
|
|
106
106
|
|
|
107
|
-
- **Name collisions.** If an explicit tool defined in the `tools` configuration has the same name as an agent-derived tool (e.g., a tool
|
|
107
|
+
- **Name collisions.** If an explicit tool defined in the `tools` configuration has the same name as an agent-derived tool (e.g., a tool with the name `ask_myAgentKey` alongside an agent keyed as `myAgentKey`), the _explicitly defined tool will take precedence_. The agent won't be converted into a tool in this conflicting case, and a warning will be logged.
|
|
108
108
|
|
|
109
109
|
This makes it straightforward to allow MCP clients to interact with your agents using natural language queries, like any other tool.
|
|
110
110
|
|
|
@@ -116,7 +116,7 @@ The description for this generated tool will be: "Ask agent `<agent.name>` a que
|
|
|
116
116
|
|
|
117
117
|
For an agent to be converted into a tool, it **must** have a non-empty `description` string property set in its configuration when it was instantiated (e.g., `new Agent({ id: 'my-agent', name: 'myAgent', description: 'This agent does X.', ... })`). If an agent is passed to `MCPServer` with a missing or empty `description`, an error will be thrown when the `MCPServer` is instantiated, and server setup will fail.
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
Clients can use MCP to access your agents' generative capabilities and ask them questions directly.
|
|
120
120
|
|
|
121
121
|
### Accessing MCP Context in Tools
|
|
122
122
|
|
|
@@ -168,6 +168,51 @@ const fetchUserData = createTool({
|
|
|
168
168
|
})
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
#### Where `authInfo` comes from
|
|
172
|
+
|
|
173
|
+
When an MCP server is served by a Mastra server, `extra.authInfo` is populated from the principal resolved by `server.auth`. Nothing extra is required:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
export const mastra = new Mastra({
|
|
177
|
+
mcpServers: { myServer },
|
|
178
|
+
server: {
|
|
179
|
+
auth: new MastraJwtAuth({ secret: process.env.JWT_SECRET! }),
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The authenticated user is mapped to `authInfo` as:
|
|
185
|
+
|
|
186
|
+
| `authInfo` field | Value |
|
|
187
|
+
| ---------------- | -------------------------------------------------------------------------- |
|
|
188
|
+
| `token` | The bearer token or session cookie value used for the request |
|
|
189
|
+
| `clientId` | The first present of `user.id`, `user.sub`, `user.userId`, `user.email` |
|
|
190
|
+
| `scopes` | `user.scopes`, `user.scope`, or `user.permissions`, normalized to an array |
|
|
191
|
+
| `extra.user` | The full user object returned by the auth provider |
|
|
192
|
+
|
|
193
|
+
If your own middleware performs the verification, set `server.mcpOptions.setRequestAuth` to build `authInfo` yourself. The hook replaces the default mapping and applies to both the streamable HTTP and SSE transports:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
export const mastra = new Mastra({
|
|
197
|
+
mcpServers: { myServer },
|
|
198
|
+
server: {
|
|
199
|
+
middleware: [verifyBearerToken], // stores the payload on the request context
|
|
200
|
+
mcpOptions: {
|
|
201
|
+
setRequestAuth: (req, requestContext) => {
|
|
202
|
+
const payload = requestContext.get('bearerPayload')
|
|
203
|
+
req.auth = {
|
|
204
|
+
token: payload.token,
|
|
205
|
+
clientId: payload.sub,
|
|
206
|
+
scopes: payload.scope.split(' '),
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Leaving `req.auth` unset inside the hook opts the request out of auth info entirely.
|
|
215
|
+
|
|
171
216
|
## Methods
|
|
172
217
|
|
|
173
218
|
These are the functions you can call on an `MCPServer` instance to control its behavior and get information.
|
|
@@ -929,7 +974,7 @@ Notification methods (`resources.notifyListChanged()`, `prompts.notifyListChange
|
|
|
929
974
|
|
|
930
975
|
## Examples
|
|
931
976
|
|
|
932
|
-
For a practical example of packaging a stdio server, see [Publish a stdio server package](https://mastra.ai/docs/mcp
|
|
977
|
+
For a practical example of packaging a stdio server, see [Publish a stdio server package](https://mastra.ai/docs/connections/mcp).
|
|
933
978
|
|
|
934
979
|
The example at the beginning of this page also demonstrates how to instantiate `MCPServer` with both tools and agents.
|
|
935
980
|
|
|
@@ -1240,7 +1285,7 @@ const customMiddleware = createOAuthMiddleware({
|
|
|
1240
1285
|
|
|
1241
1286
|
## Authentication context
|
|
1242
1287
|
|
|
1243
|
-
Tools can access request metadata via `context.mcp.extra` when using HTTP-based transports.
|
|
1288
|
+
Tools can access request metadata via `context.mcp.extra` when using HTTP-based transports. You can pass authentication info and user context, as well as custom data from your HTTP middleware to your MCP tools.
|
|
1244
1289
|
|
|
1245
1290
|
### How it works
|
|
1246
1291
|
|
|
@@ -1637,6 +1682,9 @@ const calculatorTool = createTool({
|
|
|
1637
1682
|
num2: z.number(),
|
|
1638
1683
|
operation: z.enum(['add', 'subtract']),
|
|
1639
1684
|
}),
|
|
1685
|
+
mcp: {
|
|
1686
|
+
_meta: { ui: { resourceUri: 'ui://calculator/main' } },
|
|
1687
|
+
},
|
|
1640
1688
|
execute: async ({ num1, num2, operation }) => {
|
|
1641
1689
|
const result = operation === 'add' ? num1 + num2 : num1 - num2
|
|
1642
1690
|
return {
|
|
@@ -1660,7 +1708,7 @@ const server = new MCPServer({
|
|
|
1660
1708
|
})
|
|
1661
1709
|
```
|
|
1662
1710
|
|
|
1663
|
-
Link a tool to its app resource by setting `_meta.ui.resourceUri`
|
|
1711
|
+
Link a tool to its app resource by setting `mcp._meta.ui.resourceUri` in `createTool()` to the matching `ui://` URI. The server normalizes this metadata for older hosts when listing tools. Visit [MCP Apps](https://mastra.ai/docs/connections/mcp) for the full app bridge API and usage patterns.
|
|
1664
1712
|
|
|
1665
1713
|
## Related information
|
|
1666
1714
|
|