@agent-vm/mcp-portal 0.0.63 → 0.0.64

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.
@@ -0,0 +1,19 @@
1
+ import { Tool } from "@modelcontextprotocol/sdk/types.js";
2
+
3
+ //#region src/testing/fake-upstream-mcp-server.d.ts
4
+ declare const fakeUpstreamNamespace = "upstream-mock";
5
+ interface FakeUpstreamToolCallRecord {
6
+ readonly argumentsValue: unknown;
7
+ readonly name: string;
8
+ }
9
+ interface StartedFakeUpstreamMcpServer {
10
+ readonly calls: readonly FakeUpstreamToolCallRecord[];
11
+ readonly close: () => Promise<void>;
12
+ readonly port: number;
13
+ readonly url: string;
14
+ }
15
+ declare function createFakeUpstreamTools(): readonly Tool[];
16
+ declare function startFakeUpstreamMcpServer(): Promise<StartedFakeUpstreamMcpServer>;
17
+ //#endregion
18
+ export { FakeUpstreamToolCallRecord, StartedFakeUpstreamMcpServer, createFakeUpstreamTools, fakeUpstreamNamespace, startFakeUpstreamMcpServer };
19
+ //# sourceMappingURL=fake-upstream-mcp-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-upstream-mcp-server.d.ts","names":[],"sources":["../../src/testing/fake-upstream-mcp-server.ts"],"mappings":";;;cAWa,qBAAA;AAAA,UAEI,0BAAA;EAAA,SACP,cAAA;EAAA,SACA,IAAA;AAAA;AAAA,UAGO,4BAAA;EAAA,SACP,KAAA,WAAgB,0BAAA;EAAA,SAChB,KAAA,QAAa,OAAA;EAAA,SACb,IAAA;EAAA,SACA,GAAA;AAAA;AAAA,iBA4CM,uBAAA,CAAA,YAAoC,IAAA;AAAA,iBA2B9B,0BAAA,CAAA,GAA8B,OAAA,CAAQ,4BAAA"}
@@ -0,0 +1,122 @@
1
+ import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
2
+ import { Hono } from "hono";
3
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
+ import { serve } from "@hono/node-server";
6
+ //#region src/testing/fake-upstream-mcp-server.ts
7
+ const fakeUpstreamNamespace = "upstream-mock";
8
+ function isObjectRecord(value) {
9
+ return typeof value === "object" && value !== null && !Array.isArray(value);
10
+ }
11
+ async function closeServer(server) {
12
+ await new Promise((resolve, reject) => {
13
+ server.close((error) => {
14
+ if (error) {
15
+ reject(error);
16
+ return;
17
+ }
18
+ resolve();
19
+ });
20
+ });
21
+ }
22
+ async function serveHonoOnOpenPort(app) {
23
+ return await new Promise((resolve) => {
24
+ const server = serve({
25
+ fetch: app.fetch,
26
+ hostname: "127.0.0.1",
27
+ port: 0
28
+ }, (info) => {
29
+ resolve({
30
+ port: info.port,
31
+ server
32
+ });
33
+ });
34
+ });
35
+ }
36
+ function createToolResult(name, argumentsValue) {
37
+ return {
38
+ content: [{
39
+ text: JSON.stringify({
40
+ arguments: argumentsValue,
41
+ name,
42
+ ok: true
43
+ }),
44
+ type: "text"
45
+ }],
46
+ structuredContent: {
47
+ name,
48
+ ok: true
49
+ }
50
+ };
51
+ }
52
+ function createFakeUpstreamTools() {
53
+ return [{
54
+ annotations: {
55
+ destructiveHint: false,
56
+ readOnlyHint: true
57
+ },
58
+ description: "Reads a mock record.",
59
+ inputSchema: {
60
+ additionalProperties: false,
61
+ properties: { title: { type: "string" } },
62
+ required: ["title"],
63
+ type: "object"
64
+ },
65
+ name: "read_thing"
66
+ }, {
67
+ annotations: { destructiveHint: true },
68
+ description: "Writes a mock record.",
69
+ inputSchema: {
70
+ additionalProperties: false,
71
+ properties: { title: { type: "string" } },
72
+ required: ["title"],
73
+ type: "object"
74
+ },
75
+ name: "write_thing"
76
+ }];
77
+ }
78
+ async function startFakeUpstreamMcpServer() {
79
+ const calls = [];
80
+ const tools = createFakeUpstreamTools();
81
+ const toolsByName = new Map(tools.map((tool) => [tool.name, tool]));
82
+ const app = new Hono();
83
+ app.all("/mcp", async (context) => {
84
+ const transport = new WebStandardStreamableHTTPServerTransport();
85
+ const server = new Server({
86
+ name: "portal-upstream-fixture",
87
+ version: "1.0.0"
88
+ }, { capabilities: { tools: { listChanged: false } } });
89
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
90
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
91
+ const tool = toolsByName.get(request.params.name);
92
+ if (tool === void 0) return {
93
+ content: [{
94
+ text: `Unknown tool ${request.params.name}`,
95
+ type: "text"
96
+ }],
97
+ isError: true
98
+ };
99
+ const argumentsValue = isObjectRecord(request.params.arguments) ? request.params.arguments : {};
100
+ calls.push({
101
+ argumentsValue,
102
+ name: tool.name
103
+ });
104
+ return createToolResult(tool.name, argumentsValue);
105
+ });
106
+ await server.connect(transport);
107
+ return await transport.handleRequest(context.req.raw);
108
+ });
109
+ const startedServer = await serveHonoOnOpenPort(app);
110
+ return {
111
+ calls,
112
+ close: async () => {
113
+ await closeServer(startedServer.server);
114
+ },
115
+ port: startedServer.port,
116
+ url: `http://127.0.0.1:${String(startedServer.port)}/mcp`
117
+ };
118
+ }
119
+ //#endregion
120
+ export { createFakeUpstreamTools, fakeUpstreamNamespace, startFakeUpstreamMcpServer };
121
+
122
+ //# sourceMappingURL=fake-upstream-mcp-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake-upstream-mcp-server.js","names":[],"sources":["../../src/testing/fake-upstream-mcp-server.ts"],"sourcesContent":["import { serve, type ServerType } from '@hono/node-server';\nimport { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';\nimport {\n\tCallToolRequestSchema,\n\tListToolsRequestSchema,\n\ttype CallToolResult,\n\ttype Tool,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { Hono } from 'hono';\n\nexport const fakeUpstreamNamespace = 'upstream-mock';\n\nexport interface FakeUpstreamToolCallRecord {\n\treadonly argumentsValue: unknown;\n\treadonly name: string;\n}\n\nexport interface StartedFakeUpstreamMcpServer {\n\treadonly calls: readonly FakeUpstreamToolCallRecord[];\n\treadonly close: () => Promise<void>;\n\treadonly port: number;\n\treadonly url: string;\n}\n\ninterface StartedHonoServer {\n\treadonly port: number;\n\treadonly server: ServerType;\n}\n\nfunction isObjectRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nasync function closeServer(server: ServerType): Promise<void> {\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.close((error) => {\n\t\t\tif (error) {\n\t\t\t\treject(error);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolve();\n\t\t});\n\t});\n}\n\nasync function serveHonoOnOpenPort(app: Hono): Promise<StartedHonoServer> {\n\treturn await new Promise<StartedHonoServer>((resolve) => {\n\t\tconst server = serve({ fetch: app.fetch, hostname: '127.0.0.1', port: 0 }, (info) => {\n\t\t\tresolve({ port: info.port, server });\n\t\t});\n\t});\n}\n\nfunction createToolResult(name: string, argumentsValue: unknown): CallToolResult {\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttext: JSON.stringify({ arguments: argumentsValue, name, ok: true }),\n\t\t\t\ttype: 'text',\n\t\t\t},\n\t\t],\n\t\tstructuredContent: { name, ok: true },\n\t};\n}\n\nexport function createFakeUpstreamTools(): readonly Tool[] {\n\treturn [\n\t\t{\n\t\t\tannotations: { destructiveHint: false, readOnlyHint: true },\n\t\t\tdescription: 'Reads a mock record.',\n\t\t\tinputSchema: {\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tproperties: { title: { type: 'string' } },\n\t\t\t\trequired: ['title'],\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t\tname: 'read_thing',\n\t\t},\n\t\t{\n\t\t\tannotations: { destructiveHint: true },\n\t\t\tdescription: 'Writes a mock record.',\n\t\t\tinputSchema: {\n\t\t\t\tadditionalProperties: false,\n\t\t\t\tproperties: { title: { type: 'string' } },\n\t\t\t\trequired: ['title'],\n\t\t\t\ttype: 'object',\n\t\t\t},\n\t\t\tname: 'write_thing',\n\t\t},\n\t] satisfies readonly Tool[];\n}\n\nexport async function startFakeUpstreamMcpServer(): Promise<StartedFakeUpstreamMcpServer> {\n\tconst calls: FakeUpstreamToolCallRecord[] = [];\n\tconst tools = createFakeUpstreamTools();\n\tconst toolsByName = new Map(tools.map((tool) => [tool.name, tool]));\n\tconst app = new Hono();\n\n\tapp.all('/mcp', async (context) => {\n\t\tconst transport = new WebStandardStreamableHTTPServerTransport();\n\t\tconst server = new Server(\n\t\t\t{ name: 'portal-upstream-fixture', version: '1.0.0' },\n\t\t\t{ capabilities: { tools: { listChanged: false } } },\n\t\t);\n\n\t\tserver.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));\n\t\tserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n\t\t\tconst tool = toolsByName.get(request.params.name);\n\t\t\tif (tool === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ text: `Unknown tool ${request.params.name}`, type: 'text' }],\n\t\t\t\t\tisError: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst argumentsValue = isObjectRecord(request.params.arguments)\n\t\t\t\t? request.params.arguments\n\t\t\t\t: {};\n\t\t\tcalls.push({ argumentsValue, name: tool.name });\n\t\t\treturn createToolResult(tool.name, argumentsValue);\n\t\t});\n\n\t\tawait server.connect(transport);\n\t\treturn await transport.handleRequest(context.req.raw);\n\t});\n\n\tconst startedServer = await serveHonoOnOpenPort(app);\n\treturn {\n\t\tcalls,\n\t\tclose: async () => {\n\t\t\tawait closeServer(startedServer.server);\n\t\t},\n\t\tport: startedServer.port,\n\t\turl: `http://127.0.0.1:${String(startedServer.port)}/mcp`,\n\t};\n}\n"],"mappings":";;;;;;AAWA,MAAa,wBAAwB;AAmBrC,SAAS,eAAe,OAAkD;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,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CAA0C;EAChE,MAAM,SAAS,IAAI,OAClB;GAAE,MAAM;GAA2B,SAAS;GAAS,EACrD,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,OAAO,EAAE,EAAE,CACnD;EAED,OAAO,kBAAkB,wBAAwB,aAAa,EAAE,OAAO,EAAE;EACzE,OAAO,kBAAkB,uBAAuB,OAAO,YAAY;GAClE,MAAM,OAAO,YAAY,IAAI,QAAQ,OAAO,KAAK;GACjD,IAAI,SAAS,KAAA,GACZ,OAAO;IACN,SAAS,CAAC;KAAE,MAAM,gBAAgB,QAAQ,OAAO;KAAQ,MAAM;KAAQ,CAAC;IACxE,SAAS;IACT;GAEF,MAAM,iBAAiB,eAAe,QAAQ,OAAO,UAAU,GAC5D,QAAQ,OAAO,YACf,EAAE;GACL,MAAM,KAAK;IAAE;IAAgB,MAAM,KAAK;IAAM,CAAC;GAC/C,OAAO,iBAAiB,KAAK,MAAM,eAAe;IACjD;EAEF,MAAM,OAAO,QAAQ,UAAU;EAC/B,OAAO,MAAM,UAAU,cAAc,QAAQ,IAAI,IAAI;GACpD;CAEF,MAAM,gBAAgB,MAAM,oBAAoB,IAAI;CACpD,OAAO;EACN;EACA,OAAO,YAAY;GAClB,MAAM,YAAY,cAAc,OAAO;;EAExC,MAAM,cAAc;EACpB,KAAK,oBAAoB,OAAO,cAAc,KAAK,CAAC;EACpD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-vm/mcp-portal",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "description": "Agent-scoped MCP Portal server and TypeScript helpers for composable upstream MCP tools.",
5
5
  "homepage": "https://github.com/ShravanSunder/agent-vm#readme",
6
6
  "bugs": {
@@ -39,6 +39,10 @@
39
39
  "./auth/hmac-env": {
40
40
  "types": "./dist/auth/hmac-env.d.ts",
41
41
  "import": "./dist/auth/hmac-env.js"
42
+ },
43
+ "./testing/fake-upstream-mcp-server": {
44
+ "types": "./dist/testing/fake-upstream-mcp-server.d.ts",
45
+ "import": "./dist/testing/fake-upstream-mcp-server.js"
42
46
  }
43
47
  },
44
48
  "publishConfig": {
@@ -49,7 +53,7 @@
49
53
  "@modelcontextprotocol/sdk": "^1.29.0",
50
54
  "hono": "^4.12.18",
51
55
  "zod": "^4.4.3",
52
- "@agent-vm/config-contracts": "0.0.63"
56
+ "@agent-vm/config-contracts": "0.0.64"
53
57
  },
54
58
  "devDependencies": {
55
59
  "vitest": "^4.1.5"