@mastra/mcp 1.15.1 → 1.16.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 +76 -0
- package/dist/client/actions/elicitation.d.ts +1 -1
- package/dist/client/actions/elicitation.d.ts.map +1 -1
- package/dist/client/actions/progress.d.ts +1 -1
- package/dist/client/actions/progress.d.ts.map +1 -1
- package/dist/client/actions/prompt.d.ts +1 -1
- package/dist/client/actions/prompt.d.ts.map +1 -1
- package/dist/client/actions/resource.d.ts +38 -11
- package/dist/client/actions/resource.d.ts.map +1 -1
- package/dist/client/client.d.ts +8 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/configuration.d.ts +50 -14
- package/dist/client/configuration.d.ts.map +1 -1
- package/dist/client/types.d.ts +65 -10
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/url-policy.d.ts +67 -0
- package/dist/client/url-policy.d.ts.map +1 -0
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-connections-overview.md +94 -0
- package/dist/docs/references/docs-mcp-overview.md +229 -278
- package/dist/docs/references/reference-tools-mcp-client.md +54 -0
- package/dist/docs/references/reference-tools-mcp-server.md +1 -1
- package/dist/index.cjs +2496 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2464 -234
- package/dist/index.js.map +1 -1
- package/dist/server/__tests__/mock-extra.d.ts +15 -0
- package/dist/server/__tests__/mock-extra.d.ts.map +1 -0
- package/dist/server/notificationBroadcast.d.ts +1 -1
- package/dist/server/notificationBroadcast.d.ts.map +1 -1
- package/dist/server/promptActions.d.ts +1 -1
- package/dist/server/promptActions.d.ts.map +1 -1
- package/dist/server/resourceActions.d.ts +1 -1
- package/dist/server/resourceActions.d.ts.map +1 -1
- package/dist/server/server.d.ts +10 -12
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/toolActions.d.ts +1 -1
- package/dist/server/toolActions.d.ts.map +1 -1
- package/dist/server/types.d.ts +7 -7
- package/dist/server/types.d.ts.map +1 -1
- package/dist/shared/oauth-types.d.ts +8 -6
- package/dist/shared/oauth-types.d.ts.map +1 -1
- package/package.json +18 -14
- package/dist/docs/references/docs-mcp-mcp-apps.md +0 -306
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structural view of a fetch response. Both the platform `Response`
|
|
3
|
+
* and the eventsource package's `FetchLikeResponse` (used for a caller-supplied
|
|
4
|
+
* `eventSourceInit.fetch`) satisfy it.
|
|
5
|
+
*/
|
|
6
|
+
type ResponseLike = {
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly body?: unknown;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Assert that the URL's host is in the allowlist.
|
|
12
|
+
*
|
|
13
|
+
* Matching is exact and case-insensitive against `URL.host` (hostname plus
|
|
14
|
+
* port when the URL carries a non-default port — WHATWG URL elides default
|
|
15
|
+
* ports, so `https://x.com:443` has host `x.com`). No wildcards. An empty
|
|
16
|
+
* allowlist denies every host. The URL scheme is not checked.
|
|
17
|
+
*
|
|
18
|
+
* @returns the parsed URL, for callers that need it.
|
|
19
|
+
* @throws {MastraError} `MCP_CLIENT_HOST_NOT_ALLOWED` when the host is not allowed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function assertHostAllowed(url: string | URL, allowedHosts: readonly string[], detail?: string): URL;
|
|
22
|
+
/**
|
|
23
|
+
* Post-hoc validation for responses produced by a caller-supplied fetch.
|
|
24
|
+
*
|
|
25
|
+
* A custom fetch may auto-follow redirects, so the final URL can differ from
|
|
26
|
+
* the (already validated) request URL. When `response.url` lands on a
|
|
27
|
+
* disallowed host the response is discarded by throwing — the outbound hop
|
|
28
|
+
* already happened, but the data never reaches the caller or the model.
|
|
29
|
+
*
|
|
30
|
+
* Limitation (fail-open by design): a hand-built or proxied `Response` with an
|
|
31
|
+
* empty `response.url` skips this check, because custom fetch implementations
|
|
32
|
+
* legitimately construct such responses.
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertResponseHostAllowed<R extends ResponseLike>(response: R, allowedHosts: readonly string[]): R;
|
|
35
|
+
export declare function isUrlPolicyError(error: unknown): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Wrap a caller-supplied fetch with the allowedHosts policy: the request URL is
|
|
38
|
+
* validated before the wrapped fetch runs, and the response is validated
|
|
39
|
+
* post-hoc via {@link assertResponseHostAllowed}.
|
|
40
|
+
*
|
|
41
|
+
* Variadic over the trailing arguments deliberately: the same wrapper serves
|
|
42
|
+
* the 3-arg `MastraFetchLike` (url, init, requestContext) and the 2-arg
|
|
43
|
+
* eventsource stream fetch (url, init).
|
|
44
|
+
*/
|
|
45
|
+
export declare function wrapFetchWithHostPolicy<Args extends [url: string | URL, ...rest: any[]], R extends ResponseLike>(fetchImpl: (...args: Args) => Promise<R>, allowedHosts: readonly string[]): (...args: Args) => Promise<R>;
|
|
46
|
+
/**
|
|
47
|
+
* Fetch with manual redirect handling so every redirect hop is validated
|
|
48
|
+
* against the allowlist BEFORE the hop request is sent. Platform fetch follows
|
|
49
|
+
* redirects transparently, which would bypass a per-call host check.
|
|
50
|
+
*
|
|
51
|
+
* Semantics follow platform conventions:
|
|
52
|
+
* - `Location` is resolved against the current hop's URL (relative Locations are legal).
|
|
53
|
+
* - 303 switches the method to GET and drops the body; 301/302 on POST do the same.
|
|
54
|
+
* - 307/308 preserve method and body; a non-replayable body (anything other
|
|
55
|
+
* than a string) throws rather than silently re-sending an empty body.
|
|
56
|
+
* - 301/302 on non-POST methods preserve the method and body, matching
|
|
57
|
+
* platform behavior.
|
|
58
|
+
* - The `Authorization` header is not carried across hops to a different
|
|
59
|
+
* origin (scheme, host, or port change), matching the WHATWG Fetch
|
|
60
|
+
* credential-stripping rule — same host over a downgraded scheme still
|
|
61
|
+
* drops the header.
|
|
62
|
+
* - A redirect status with no `Location` header throws.
|
|
63
|
+
* - More than {@link MAX_REDIRECT_HOPS} hops throws.
|
|
64
|
+
*/
|
|
65
|
+
export declare function fetchFollowingAllowedRedirects(fetchImpl: (url: string | URL, init?: RequestInit) => Promise<Response>, url: string | URL, init: RequestInit | undefined, allowedHosts: readonly string[]): Promise<Response>;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=url-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-policy.d.ts","sourceRoot":"","sources":["../../src/client/url-policy.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,KAAK,YAAY,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAgDtE;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,YAAY,EAAE,SAAS,MAAM,EAAE,EAC/B,MAAM,SAA8B,GACnC,GAAG,CAML;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,CAcjH;AAmBD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAQxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,SAAS,YAAY,EAC9G,SAAS,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EACxC,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAM/B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,8BAA8B,CAClD,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,EACvE,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,OAAO,CAAC,QAAQ,CAAC,CAoEnB"}
|
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.16.0-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -16,8 +16,8 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
16
16
|
|
|
17
17
|
### Docs
|
|
18
18
|
|
|
19
|
-
- [
|
|
20
|
-
- [MCP overview](references/docs-mcp-overview.md) -
|
|
19
|
+
- [Connections overview](references/docs-connections-overview.md) - Connect Mastra to remote agents, coding agents, provider software development kit runtimes, and external tools and resources.
|
|
20
|
+
- [MCP overview](references/docs-mcp-overview.md) - Connect Mastra agents to external MCP servers, expose Mastra tools through MCPServer, and build interactive MCP Apps for Studio.
|
|
21
21
|
- [Fine-Grained Authorization (FGA)](references/docs-server-auth-fga.md) - Add resource-level authorization to your Mastra application with FGA providers.
|
|
22
22
|
|
|
23
23
|
### Reference
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
+
|
|
3
|
+
# Connections overview
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
- [**Agent-to-Agent (A2A)**](https://mastra.ai/docs/agents/a2a): Expose or consume remote agents across service, framework, vendor, and language boundaries.
|
|
8
|
+
- [**Agent Client Protocol (ACP)**](https://mastra.ai/docs/agents/acp): Run compatible coding-agent processes as Mastra tools or subagents.
|
|
9
|
+
- [**SDK agents**](https://mastra.ai/docs/agents/sdk-agents): Register Claude, Cursor, or OpenAI SDK-backed agents while the provider SDK retains control of the runtime, tools, permissions, and agent loop.
|
|
10
|
+
- [**Model Context Protocol (MCP)**](https://mastra.ai/docs/mcp/overview): Connect agents to external tools and resources, or expose Mastra agents, tools, workflows, prompts, and resources to MCP-compatible systems.
|
|
11
|
+
|
|
12
|
+
## When to use connections
|
|
13
|
+
|
|
14
|
+
Use connections when you need to:
|
|
15
|
+
|
|
16
|
+
- Delegate work to an agent running in another service or runtime.
|
|
17
|
+
- Run a coding agent against a project workspace.
|
|
18
|
+
- Add a provider-native agent without replacing its SDK runtime or agent loop.
|
|
19
|
+
- Connect agents to external tools and resources or publish Mastra capabilities to other systems.
|
|
20
|
+
|
|
21
|
+
## Get started
|
|
22
|
+
|
|
23
|
+
Start with the boundary you need to cross. Use [A2A](https://mastra.ai/docs/agents/a2a) for remote agent endpoints, [ACP](https://mastra.ai/docs/agents/acp) for coding-agent processes, [SDK agents](https://mastra.ai/docs/agents/sdk-agents) for provider-owned runtimes, or [MCP](https://mastra.ai/docs/mcp/overview) for tools and resources.
|
|
24
|
+
|
|
25
|
+
**A2A**:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { A2AAgent } from '@mastra/core/a2a'
|
|
29
|
+
|
|
30
|
+
const agent = new A2AAgent({
|
|
31
|
+
url: 'https://agent.example.com/.well-known/agent-card.json',
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const result = await agent.generate('Summarize the latest report')
|
|
35
|
+
console.log(result.text)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**ACP**:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { AcpAgent } from '@mastra/acp'
|
|
42
|
+
|
|
43
|
+
const agent = new AcpAgent({
|
|
44
|
+
id: 'coding-agent',
|
|
45
|
+
description: 'Inspects and edits code',
|
|
46
|
+
command: 'claude',
|
|
47
|
+
args: ['--acp'],
|
|
48
|
+
persistSession: false,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const result = await agent.generate('Review this project')
|
|
52
|
+
console.log(result.text)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**SDK agents**:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { OpenAISDKAgent } from '@mastra/openai'
|
|
59
|
+
|
|
60
|
+
const agent = new OpenAISDKAgent({
|
|
61
|
+
id: 'openai-agent',
|
|
62
|
+
description: 'Answers project questions',
|
|
63
|
+
sdkOptions: {
|
|
64
|
+
name: 'Project assistant',
|
|
65
|
+
model: 'gpt-5',
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const result = await agent.generate('Explain agent loops in one sentence')
|
|
70
|
+
console.log(result.text)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**MCP**:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { MCPClient } from '@mastra/mcp'
|
|
77
|
+
|
|
78
|
+
const client = new MCPClient({
|
|
79
|
+
id: 'wikipedia-client',
|
|
80
|
+
servers: {
|
|
81
|
+
wikipedia: {
|
|
82
|
+
command: 'npx',
|
|
83
|
+
args: ['-y', 'wikipedia-mcp'],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const tools = await client.listTools()
|
|
90
|
+
console.log(Object.keys(tools))
|
|
91
|
+
} finally {
|
|
92
|
+
await client.disconnect()
|
|
93
|
+
}
|
|
94
|
+
```
|