feat: add scoped history and artifacts
This commit is contained in:
@@ -5,6 +5,7 @@ import { bindSessionCredential, releaseSessionCredential } from "../../src/produ
|
||||
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
||||
import { startQueryMcpServer } from "../../src/mcp/query-server.js";
|
||||
import { setRuntimeSessionContext, removeRuntimeSessionContext } from "../../src/runtime/sessionContext.js";
|
||||
import { PRODUCT_MCP_TOOLS, QUERY_MCP_TOOL_IDS } from "../../src/runtime/product-mcp-tools.js";
|
||||
|
||||
const python = process.env.MCP_TEST_PYTHON;
|
||||
const root = process.env.MCP_TEST_SERVER_ROOT;
|
||||
@@ -44,23 +45,31 @@ try {
|
||||
};
|
||||
const client = new McpQueryClient({ issuer: "http://localhost/realms/test", resource, audience: "tjwater-mcp", clientId: "tjwater-agent-mcp", clientSecret: "fixture" }, http);
|
||||
const catalog = await client.prepare();
|
||||
if (catalog.length !== 35) throw new Error("Query catalog discovery failed");
|
||||
if (catalog.length !== PRODUCT_MCP_TOOLS.length) throw new Error("Query catalog discovery failed");
|
||||
if (!catalog.some((tool) => tool.name === "run_simulation" && tool.inputSchema.properties?.start_time && tool.inputSchema.properties?.output_node_ids)) throw new Error("Standard hydraulic simulation schema missing");
|
||||
bindSessionCredential(session, { authorization: `Bearer ${fixtureJwt("source")}`, projectId: "d44a9241-de48-4e60-9348-867dc466a031" });
|
||||
setRuntimeSessionContext({ sessionId: session, clientSessionId: session, actorKey: "fixture", traceId: "fixture", projectId: "d44a9241-de48-4e60-9348-867dc466a031", projectKey: "fixture-project", purpose: "ordinary_chat" });
|
||||
gateway = startQueryMcpServer({ internalToken: "MCP_TEST_ONLY", productClient: client, productTools: catalog, resolveReader: async () => null, executeLocal: async () => { throw new Error("unused fixture query"); } });
|
||||
nativeClient = new Client({ name: "fixture-native", version: "1" }, { versionNegotiation: { mode: { pin: "2026-07-28" } } });
|
||||
await nativeClient.connect(new StreamableHTTPClientTransport(new URL(gateway.url), { requestInit: { headers: { "x-agent-internal-token": "MCP_TEST_ONLY" } } }));
|
||||
if ((await nativeClient.listTools()).tools.length !== 41) throw new Error("Merged MCP query catalog discovery failed");
|
||||
if ((await nativeClient.listTools()).tools.length !== QUERY_MCP_TOOL_IDS.length) throw new Error("Merged MCP query catalog discovery failed");
|
||||
const result = await nativeClient.callTool({ name: "list_elements", arguments: { element_type: "pipe", limit: 1 }, _meta: { "ai.opencode/sessionID": session } });
|
||||
if (result.isError || JSON.stringify((result.structuredContent as { data?: unknown } | undefined)?.data) !== '[{"id":"P-1"}]') throw new Error("Typed query execution failed");
|
||||
const nearbyTool = catalog.find((tool) => tool.name === "query_nearby_elements");
|
||||
if (!nearbyTool?.inputSchema.properties?.center) throw new Error("Nearby model tool schema missing");
|
||||
const nearby = await nativeClient.callTool({ name: "query_nearby_elements", arguments: { center: [121.5, 30.9], radius_m: 500, limit: 5 }, _meta: { "ai.opencode/sessionID": session } });
|
||||
if (nearby.isError) throw new Error("Nearby model query failed through merged MCP");
|
||||
for (const [name, input] of [
|
||||
["get_project_info", {}],
|
||||
["get_node_connections", { node_id: "J1", limit: 1 }],
|
||||
["query_network_extent", { bounds: [121, 31, 121.1, 31.1], limit: 1 }],
|
||||
] as const) {
|
||||
const response = await nativeClient.callTool({ name, arguments: input, _meta: { "ai.opencode/sessionID": session } });
|
||||
if (response.isError) throw new Error(`Extended tool failed through merged MCP: ${name}`);
|
||||
}
|
||||
if (!requests.includes("server/discover") || !requests.includes("tools/call") || requests.includes("initialize") || requests.includes("GET")) throw new Error("Transport used unexpected protocol requests");
|
||||
if (grants.join(",") !== "client_credentials,urn:ietf:params:oauth:grant-type:token-exchange") throw new Error("OAuth grants were not validated");
|
||||
console.log("PASS: local MCP 41-tool discovery, real Server schemas, OAuth discovery, resource-bound grants, host binding, query and revocation over MCP HTTP");
|
||||
console.log(`PASS: local MCP ${QUERY_MCP_TOOL_IDS.length}-tool discovery, real Server schemas, OAuth discovery, resource-bound grants, host binding, extended query and revocation over MCP HTTP`);
|
||||
} finally {
|
||||
await nativeClient?.close();
|
||||
await gateway?.close();
|
||||
|
||||
Reference in New Issue
Block a user