@mastra/mcp 0.11.3-alpha.1 → 0.11.3-alpha.3

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/client/configuration.d.ts +1 -1
  3. package/dist/client/configuration.d.ts.map +1 -1
  4. package/dist/client/promptActions.d.ts +1 -1
  5. package/dist/client/promptActions.d.ts.map +1 -1
  6. package/dist/index.cjs +223 -115
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.js +225 -118
  9. package/dist/index.js.map +1 -1
  10. package/dist/server/server.d.ts +6 -5
  11. package/dist/server/server.d.ts.map +1 -1
  12. package/dist/server/types.d.ts +69 -5
  13. package/dist/server/types.d.ts.map +1 -1
  14. package/package.json +15 -2
  15. package/.turbo/turbo-build.log +0 -4
  16. package/eslint.config.js +0 -11
  17. package/integration-tests/node_modules/.bin/tsc +0 -21
  18. package/integration-tests/node_modules/.bin/tsserver +0 -21
  19. package/integration-tests/node_modules/.bin/vitest +0 -21
  20. package/integration-tests/package.json +0 -29
  21. package/integration-tests/src/mastra/agents/weather.ts +0 -34
  22. package/integration-tests/src/mastra/index.ts +0 -15
  23. package/integration-tests/src/mastra/mcp/index.ts +0 -46
  24. package/integration-tests/src/mastra/tools/weather.ts +0 -13
  25. package/integration-tests/src/server.test.ts +0 -238
  26. package/integration-tests/tsconfig.json +0 -13
  27. package/integration-tests/vitest.config.ts +0 -14
  28. package/src/__fixtures__/fire-crawl-complex-schema.ts +0 -1013
  29. package/src/__fixtures__/server-weather.ts +0 -16
  30. package/src/__fixtures__/stock-price.ts +0 -128
  31. package/src/__fixtures__/tools.ts +0 -94
  32. package/src/__fixtures__/weather.ts +0 -269
  33. package/src/client/client.test.ts +0 -585
  34. package/src/client/client.ts +0 -628
  35. package/src/client/configuration.test.ts +0 -856
  36. package/src/client/configuration.ts +0 -468
  37. package/src/client/elicitationActions.ts +0 -26
  38. package/src/client/index.ts +0 -3
  39. package/src/client/promptActions.ts +0 -70
  40. package/src/client/resourceActions.ts +0 -119
  41. package/src/index.ts +0 -2
  42. package/src/server/index.ts +0 -2
  43. package/src/server/promptActions.ts +0 -48
  44. package/src/server/resourceActions.ts +0 -90
  45. package/src/server/server-logging.test.ts +0 -181
  46. package/src/server/server.test.ts +0 -2142
  47. package/src/server/server.ts +0 -1445
  48. package/src/server/types.ts +0 -59
  49. package/tsconfig.build.json +0 -9
  50. package/tsconfig.json +0 -5
  51. package/tsup.config.ts +0 -17
  52. package/vitest.config.ts +0 -8
@@ -1,7 +1,7 @@
1
1
  import type * as http from 'node:http';
2
- import type { ToolsInput, Agent } from '@mastra/core/agent';
2
+ import type { Agent, ToolsInput } from '@mastra/core/agent';
3
3
  import { MCPServerBase } from '@mastra/core/mcp';
4
- import type { MCPServerConfig, ServerInfo, ServerDetailInfo, ConvertedTool, MCPServerHonoSSEOptions, MCPServerSSEOptions, MCPToolType } from '@mastra/core/mcp';
4
+ import type { ServerInfo, ServerDetailInfo, ConvertedTool, MCPServerHonoSSEOptions, MCPServerSSEOptions, MCPToolType } from '@mastra/core/mcp';
5
5
  import type { Workflow } from '@mastra/core/workflows';
6
6
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
7
  import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
@@ -11,7 +11,7 @@ import type { SSEStreamingApi } from 'hono/streaming';
11
11
  import { SSETransport } from 'hono-mcp-server-sse-transport';
12
12
  import { ServerPromptActions } from './promptActions.js';
13
13
  import { ServerResourceActions } from './resourceActions.js';
14
- import type { MCPServerPrompts, MCPServerResources, ElicitationActions } from './types.js';
14
+ import type { MCPServerPrompts, MCPServerResources, ElicitationActions, MCPServerConfig, MCPToolsInput } from './types.js';
15
15
  export declare class MCPServer extends MCPServerBase {
16
16
  private server;
17
17
  private stdioTransport?;
@@ -25,6 +25,7 @@ export declare class MCPServer extends MCPServerBase {
25
25
  private definedPrompts?;
26
26
  private promptOptions?;
27
27
  private subscriptions;
28
+ private currentLoggingLevel;
28
29
  readonly resources: ServerResourceActions;
29
30
  readonly prompts: ServerPromptActions;
30
31
  readonly elicitation: ElicitationActions;
@@ -84,12 +85,12 @@ export declare class MCPServer extends MCPServerBase {
84
85
  /**
85
86
  * Convert and validate all provided tools, logging registration status.
86
87
  * Also converts agents and workflows into tools.
87
- * @param tools Tool definitions
88
+ * @param tools Tool definitions (supports ToolsInput, MCPToolsInput)
88
89
  * @param agentsConfig Agent definitions to be converted to tools, expected from MCPServerConfig
89
90
  * @param workflowsConfig Workflow definitions to be converted to tools, expected from MCPServerConfig
90
91
  * @returns Converted tools registry
91
92
  */
92
- convertTools(tools: ToolsInput, agentsConfig?: Record<string, Agent>, workflowsConfig?: Record<string, Workflow>): Record<string, ConvertedTool>;
93
+ convertTools(tools: ToolsInput | MCPToolsInput, agentsConfig?: Record<string, Agent>, workflowsConfig?: Record<string, Workflow>): Record<string, ConvertedTool>;
93
94
  /**
94
95
  * Start the MCP server using stdio transport (for Windsurf integration).
95
96
  */
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,mBAAmB,EACnB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAK1B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2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AG,CAAC;QAAC,YAAY,CAAC,EAAE,GAAG,CAAC;QAAC,QAAQ,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,SAAS;IAgBnH;;;;;;;OAOG;IACU,WAAW,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EACT,gBAAgB,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3D,OAAO,CAAC,GAAG,CAAC;CAiFhB"}
@@ -1,6 +1,8 @@
1
- import type { InternalCoreTool } from '@mastra/core/tools';
1
+ import type { MCPServerConfig as BaseMCPServerConfig } from '@mastra/core/mcp';
2
+ import type { InternalCoreTool, ToolAction, VercelTool, VercelToolV5 } from '@mastra/core/tools';
2
3
  import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
4
  import type { ElicitRequest, ElicitResult, Prompt, PromptMessage, Resource, ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
5
+ import type { z } from 'zod';
4
6
  export type MCPServerResourceContentCallback = ({ uri, }: {
5
7
  uri: string;
6
8
  }) => Promise<MCPServerResourceContent | MCPServerResourceContent[]>;
@@ -27,15 +29,77 @@ export type ElicitationActions = {
27
29
  sendRequest: (request: ElicitRequest['params']) => Promise<ElicitResult>;
28
30
  };
29
31
  export type MCPRequestHandlerExtra = RequestHandlerExtra<any, any>;
30
- export type MCPTool = {
32
+ export type MCPTool<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined> = {
31
33
  id?: InternalCoreTool['id'];
32
34
  description?: InternalCoreTool['description'];
33
- parameters: InternalCoreTool['parameters'];
34
- outputSchema?: InternalCoreTool['outputSchema'];
35
- execute: (params: any, options: Parameters<NonNullable<InternalCoreTool['execute']>>[1] & {
35
+ parameters: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> : any;
36
+ outputSchema?: TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : any;
37
+ execute: (params: {
38
+ context: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> : any;
39
+ }, options: Parameters<NonNullable<InternalCoreTool['execute']>>[1] & {
36
40
  elicitation: ElicitationActions;
37
41
  extra: MCPRequestHandlerExtra;
38
42
  }) => Promise<any>;
39
43
  };
44
+ /**
45
+ * Enhanced execute options for MCP tools that includes elicitation and extra context
46
+ */
47
+ export interface MCPToolExecuteOptions<TSchemaIn extends z.ZodSchema | undefined = undefined> {
48
+ context: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> : any;
49
+ elicitation: ElicitationActions;
50
+ extra: MCPRequestHandlerExtra;
51
+ }
52
+ /**
53
+ * Action interface for MCP tools
54
+ */
55
+ export interface MCPToolAction<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined> {
56
+ id: string;
57
+ description: string;
58
+ inputSchema?: TSchemaIn;
59
+ outputSchema?: TSchemaOut;
60
+ execute: (params: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> : any, options: MCPToolExecuteOptions<TSchemaIn>) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : any>;
61
+ }
62
+ /**
63
+ * Creates an MCP tool with proper typing for the MCP server environment.
64
+ * Similar to createTool but specifically designed for MCP tools with elicitation support.
65
+ *
66
+ * @param opts Tool action configuration
67
+ * @returns MCPTool instance
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const mcpTool = createMCPTool({
72
+ * id: 'weather',
73
+ * description: 'Get weather information',
74
+ * inputSchema: z.object({
75
+ * city: z.string(),
76
+ * }),
77
+ * outputSchema: z.object({
78
+ * temperature: z.number(),
79
+ * condition: z.string(),
80
+ * }),
81
+ * execute: async (params, { context, elicitation, extra }) => {
82
+ * // params contains the validated input: { city: string }
83
+ * // context is the same as params for convenience
84
+ * // Can use elicitation.sendRequest() for interactive prompts
85
+ * // Access extra MCP context via extra parameter
86
+ * return { temperature: 72, condition: 'sunny' };
87
+ * },
88
+ * });
89
+ * ```
90
+ */
91
+ export declare function createMCPTool<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined>(opts: MCPToolAction<TSchemaIn, TSchemaOut>): MCPTool;
92
+ /**
93
+ * MCP-specific tools input that supports MCPToolAction and MCPTool types in addition to regular tools
94
+ */
95
+ export type MCPToolsInput = Record<string, ToolAction<any, any, any> | VercelTool | VercelToolV5 | MCPToolAction<any, any> | MCPTool>;
96
+ /**
97
+ * Enhanced MCPServerConfig that supports MCP-specific tool types.
98
+ * This overrides the base MCPServerConfig from @mastra/core/mcp to accept our enhanced tool types.
99
+ */
100
+ export interface MCPServerConfig extends Omit<BaseMCPServerConfig, 'tools'> {
101
+ /** The tools that this MCP server will expose. Supports regular tools, MCP tool actions, or MCP tools. */
102
+ tools: MCPToolsInput;
103
+ }
40
104
  export type { Resource, ResourceTemplate };
41
105
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,MAAM,EACN,aAAa,EACb,QAAQ,EACR,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAE5C,MAAM,MAAM,gCAAgC,GAAG,CAAC,EAC9C,GAAG,GACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;CACb,KAAK,OAAO,CAAC,wBAAwB,GAAG,wBAAwB,EAAE,CAAC,CAAC;AACrE,MAAM,MAAM,wBAAwB,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC7E,MAAM,MA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AEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAChC,MAAM,EACN,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAC1F,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACzE,0GAA0G;IAC1G,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.11.3-alpha.1",
3
+ "version": "0.11.3-alpha.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CHANGELOG.md"
11
+ ],
8
12
  "exports": {
9
13
  ".": {
10
14
  "import": {
@@ -54,7 +58,16 @@
54
58
  "zod-to-json-schema": "^3.24.6",
55
59
  "@internal/lint": "0.0.34",
56
60
  "@internal/types-builder": "0.0.9",
57
- "@mastra/core": "0.15.3-alpha.4"
61
+ "@mastra/core": "0.15.3-alpha.6"
62
+ },
63
+ "homepage": "https://mastra.ai",
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "git+https://github.com/mastra-ai/mastra.git",
67
+ "directory": "packages/mcp"
68
+ },
69
+ "bugs": {
70
+ "url": "https://github.com/mastra-ai/mastra/issues"
58
71
  },
59
72
  "scripts": {
60
73
  "build": "tsup --silent --config tsup.config.ts",
@@ -1,4 +0,0 @@
1
-
2
- > @mastra/mcp@0.11.3-alpha.1 build /home/runner/work/mastra/mastra/packages/mcp
3
- > tsup --silent --config tsup.config.ts
4
-
package/eslint.config.js DELETED
@@ -1,11 +0,0 @@
1
- import { createConfig } from '@internal/lint/eslint';
2
-
3
- const config = await createConfig();
4
-
5
- /** @type {import("eslint").Linter.Config[]} */
6
- export default [
7
- ...config,
8
- {
9
- ignores: ['**/integration-tests/**'],
10
- },
11
- ];
@@ -1,21 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/bin/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/bin/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
19
- else
20
- exec node "$basedir/../typescript/bin/tsc" "$@"
21
- fi
@@ -1,21 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/bin/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/bin/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules/typescript/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/typescript@5.8.3/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
19
- else
20
- exec node "$basedir/../typescript/bin/tsserver" "$@"
21
- fi
@@ -1,21 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.11_@vitest+ui@3.2.3_jiti@2.4.2_jsdom_70e728ef477f1e37b982af437efd45b2/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.11_@vitest+ui@3.2.3_jiti@2.4.2_jsdom_70e728ef477f1e37b982af437efd45b2/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.11_@vitest+ui@3.2.3_jiti@2.4.2_jsdom_70e728ef477f1e37b982af437efd45b2/node_modules/vitest/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/vitest@3.2.4_@types+debug@4.1.12_@types+node@20.19.11_@vitest+ui@3.2.3_jiti@2.4.2_jsdom_70e728ef477f1e37b982af437efd45b2/node_modules:/home/runner/work/mastra/mastra/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../vitest/vitest.mjs" "$@"
19
- else
20
- exec node "$basedir/../vitest/vitest.mjs" "$@"
21
- fi
@@ -1,29 +0,0 @@
1
- {
2
- "name": "mcp-server-integration-tests",
3
- "private": true,
4
- "version": "0.1.0",
5
- "scripts": {
6
- "test:mcp": "vitest run ./src/server.test.ts",
7
- "dev": "mastra dev"
8
- },
9
- "dependencies": {
10
- "@ai-sdk/openai": "^1.3.24",
11
- "@ai-sdk/react": "^1.2.12",
12
- "@mastra/client-js": "workspace:*",
13
- "@mastra/mcp": "workspace:*",
14
- "dotenv": "^16.6.1",
15
- "zod": "^3.25.76"
16
- },
17
- "devDependencies": {
18
- "@mastra/core": "workspace:*",
19
- "@testing-library/react": "^16.3.0",
20
- "@types/node": "^20.17.57",
21
- "get-port": "^7.1.0",
22
- "mastra": "workspace:*",
23
- "typescript": "^5.8.3",
24
- "vitest": "^3.2.4"
25
- },
26
- "peerDependencies": {
27
- "@mastra/core": ">=0.10.7-0 <0.16.0-0"
28
- }
29
- }
@@ -1,34 +0,0 @@
1
- import { openai } from '@ai-sdk/openai';
2
- import { createTool } from '@mastra/core/tools';
3
- import { Agent } from '@mastra/core/agent';
4
- import { z } from 'zod';
5
- import { weatherTool } from '../tools/weather';
6
- import { MCPClient } from '@mastra/mcp';
7
-
8
- const client = new MCPClient({
9
- id: 'weather-server',
10
- servers: {
11
- weather: {
12
- url: new URL(`http://localhost:4114/api/mcp/myMcpServer/mcp`),
13
- },
14
- },
15
- });
16
-
17
- export const weatherAgent = new Agent({
18
- name: 'test',
19
- instructions:
20
- 'You are a weather agent. When asked about weather in any city, use the get_weather tool with the city name as the postal code. When asked for clipboard contents you also get that.',
21
- model: openai('gpt-4o'),
22
- tools: async () => {
23
- const tools = await client.getTools();
24
- return {
25
- get_weather: weatherTool,
26
- clipboard: createTool({
27
- id: 'clipboard',
28
- description: 'Returns the contents of the users clipboard',
29
- inputSchema: z.object({}),
30
- }),
31
- ...tools,
32
- };
33
- },
34
- });
@@ -1,15 +0,0 @@
1
- import { Mastra } from '@mastra/core';
2
- import { weatherAgent } from './agents/weather';
3
- import { myMcpServer } from './mcp';
4
-
5
- export const mastra = new Mastra({
6
- agents: {
7
- test: weatherAgent,
8
- },
9
- mcpServers: {
10
- myMcpServer,
11
- },
12
- server: {
13
- port: 4114,
14
- },
15
- });
@@ -1,46 +0,0 @@
1
- import { createTool } from '@mastra/core/tools';
2
- import { MCPServer } from '@mastra/mcp';
3
- import { z } from 'zod';
4
-
5
- export const myMcpServer = new MCPServer({
6
- name: 'My Calculation & Data MCP Server',
7
- version: '1.0.0',
8
- tools: {
9
- calculator: createTool({
10
- id: 'calculator',
11
- description: 'Performs basic arithmetic operations (add, subtract).',
12
- inputSchema: z.object({
13
- num1: z.number().describe('The first number.'),
14
- num2: z.number().describe('The second number.'),
15
- operation: z.enum(['add', 'subtract']).describe('The operation to perform.'),
16
- }),
17
- execute: async ({ context }) => {
18
- const { num1, num2, operation } = context;
19
- if (operation === 'add') {
20
- return num1 + num2;
21
- }
22
- if (operation === 'subtract') {
23
- return num1 - num2;
24
- }
25
- throw new Error('Invalid operation');
26
- },
27
- }),
28
- fetchWeather: createTool({
29
- id: 'fetchWeather',
30
- description: 'Fetches a (simulated) weather forecast for a given city.',
31
- inputSchema: z.object({
32
- city: z.string().describe('The city to get weather for, e.g., London, Paris.'),
33
- }),
34
- execute: async ({ context }) => {
35
- const { city } = context;
36
- const temperatures = {
37
- london: '15°C',
38
- paris: '18°C',
39
- tokyo: '22°C',
40
- };
41
- const temp = temperatures[city.toLowerCase() as keyof typeof temperatures] || '20°C';
42
- return `The weather in ${city} is ${temp} and sunny.`;
43
- },
44
- }),
45
- },
46
- });
@@ -1,13 +0,0 @@
1
- import { createTool } from '@mastra/core/tools';
2
- import { z } from 'zod';
3
-
4
- export const weatherTool = createTool({
5
- id: 'get_weather',
6
- description: 'Get the weather for a given location',
7
- inputSchema: z.object({
8
- postalCode: z.string().describe('The location to get the weather for'),
9
- }),
10
- execute: async ({ context: { postalCode } }) => {
11
- return `The weather in ${postalCode} is sunny. It is currently 70 degrees and feels like 65 degrees.`;
12
- },
13
- });