@graxia/mcp 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +169 -2
- package/dist/auth/bearer.d.ts +17 -0
- package/dist/auth/bearer.d.ts.map +1 -0
- package/dist/auth/metadata.d.ts +8 -0
- package/dist/auth/metadata.d.ts.map +1 -0
- package/dist/auth/principal.d.ts +17 -0
- package/dist/auth/principal.d.ts.map +1 -0
- package/dist/auth/resolve.d.ts +4 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/scopes.d.ts +14 -0
- package/dist/auth/scopes.d.ts.map +1 -0
- package/dist/auth/types.d.ts +70 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/body.d.ts +6 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/calls.d.ts +14 -0
- package/dist/calls.d.ts.map +1 -0
- package/dist/codes.d.ts +21 -0
- package/dist/codes.d.ts.map +1 -0
- package/dist/context.d.ts +20 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/cors.d.ts +7 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/create.d.ts +29 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1533 -0
- package/dist/index.js.map +45 -0
- package/dist/operations/build.d.ts +10 -0
- package/dist/operations/build.d.ts.map +1 -0
- package/dist/operations/constraint.d.ts +16 -0
- package/dist/operations/constraint.d.ts.map +1 -0
- package/dist/operations/documents.d.ts +13 -0
- package/dist/operations/documents.d.ts.map +1 -0
- package/dist/operations/input-schema.d.ts +12 -0
- package/dist/operations/input-schema.d.ts.map +1 -0
- package/dist/operations/input-type.d.ts +18 -0
- package/dist/operations/input-type.d.ts.map +1 -0
- package/dist/operations/naming.d.ts +5 -0
- package/dist/operations/naming.d.ts.map +1 -0
- package/dist/operations/output-schema.d.ts +11 -0
- package/dist/operations/output-schema.d.ts.map +1 -0
- package/dist/operations/problems.d.ts +27 -0
- package/dist/operations/problems.d.ts.map +1 -0
- package/dist/operations/register.d.ts +20 -0
- package/dist/operations/register.d.ts.map +1 -0
- package/dist/operations/types.d.ts +49 -0
- package/dist/operations/types.d.ts.map +1 -0
- package/dist/operations/variable-usage.d.ts +16 -0
- package/dist/operations/variable-usage.d.ts.map +1 -0
- package/dist/operations/visible.d.ts +10 -0
- package/dist/operations/visible.d.ts.map +1 -0
- package/dist/options.d.ts +116 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/origin-options.d.ts +9 -0
- package/dist/origin-options.d.ts.map +1 -0
- package/dist/origin.d.ts +18 -0
- package/dist/origin.d.ts.map +1 -0
- package/dist/pipeline.d.ts +16 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/refusal.d.ts +4 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/tools/execute.d.ts +32 -0
- package/dist/tools/execute.d.ts.map +1 -0
- package/dist/tools/guard.d.ts +8 -0
- package/dist/tools/guard.d.ts.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/operation.d.ts +35 -0
- package/dist/tools/operation.d.ts.map +1 -0
- package/dist/tools/result.d.ts +13 -0
- package/dist/tools/result.d.ts.map +1 -0
- package/dist/tools/schema.d.ts +319 -0
- package/dist/tools/schema.d.ts.map +1 -0
- package/dist/tools/strict.d.ts +12 -0
- package/dist/tools/strict.d.ts.map +1 -0
- package/dist/toolset.d.ts +30 -0
- package/dist/toolset.d.ts.map +1 -0
- package/dist/view-cache.d.ts +13 -0
- package/dist/view-cache.d.ts.map +1 -0
- package/dist/view.d.ts +16 -0
- package/dist/view.d.ts.map +1 -0
- package/docs/README.md +9 -0
- package/docs/guide/auth.md +247 -0
- package/docs/guide/getting-started.md +82 -0
- package/docs/guide/operations.md +221 -0
- package/docs/guide/security.md +122 -0
- package/docs/guide/tools.md +102 -0
- package/docs/roadmap.md +32 -0
- package/docs/troubleshooting-auth.md +101 -0
- package/docs/troubleshooting.md +205 -0
- package/package.json +71 -5
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/auth/principal.ts", "../src/create.ts", "../src/refusal.ts", "../src/auth/bearer.ts", "../src/auth/metadata.ts", "../src/auth/resolve.ts", "../src/auth/scopes.ts", "../src/calls.ts", "../src/context.ts", "../src/cors.ts", "../src/origin.ts", "../src/origin-options.ts", "../src/body.ts", "../src/pipeline.ts", "../src/server.ts", "../src/tools/execute.ts", "../src/tools/operation.ts", "../src/tools/result.ts", "../src/tools/guard.ts", "../src/operations/register.ts", "../src/tools/index.ts", "../src/tools/schema.ts", "../src/view.ts", "../src/tools/strict.ts", "../src/toolset.ts", "../src/operations/build.ts", "../src/operations/documents.ts", "../src/operations/input-schema.ts", "../src/operations/constraint.ts", "../src/operations/input-type.ts", "../src/operations/variable-usage.ts", "../src/operations/naming.ts", "../src/operations/output-schema.ts", "../src/operations/problems.ts", "../src/operations/visible.ts", "../src/view-cache.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { McpAuthInfo } from './types';\n\nconst storage = new AsyncLocalStorage<McpAuthInfo | undefined>();\n\n/**\n * Runs `fn` with `info` as the verified principal (`mcpAuth()` reads it).\n * `undefined` is stored too, so an instance without `auth` called from inside\n * another instance's tool call does not see that one's principal.\n */\nexport function runAs<T>(info: McpAuthInfo | undefined, fn: () => T): T {\n\treturn storage.run(info, fn);\n}\n\n/**\n * The verified token of the MCP request being handled, for graxia's `context`\n * builder and resolvers: the verification already happened, do not repeat it.\n * `undefined` outside a tool call, and when `createMcp` has no `auth`.\n *\n * @example\n * createGraxia({ schema, context: () => ({ user: mcpAuth()?.subject }) });\n */\nexport function mcpAuth(): McpAuthInfo | undefined {\n\treturn storage.getStore();\n}\n",
|
|
6
|
+
"import { createMcpHandler } from '@modelcontextprotocol/server';\nimport { authenticate } from './auth/bearer';\nimport { metadataHandler } from './auth/metadata';\nimport { runAs } from './auth/principal';\nimport { resolveAuth } from './auth/resolve';\nimport { writeStepUp } from './auth/scopes';\nimport type { McpAuthOptions } from './auth/types';\nimport { toolCallsOf } from './calls';\nimport { createContextCarrier } from './context';\nimport { corsOrigin, withCors } from './cors';\nimport type { Mcp, McpHost, McpOptions } from './options';\nimport { defaultHosts } from './origin';\nimport { checkOriginOptions } from './origin-options';\nimport { admit, type PipelineSettings } from './pipeline';\nimport { refusal } from './refusal';\nimport { serverFactory } from './server';\nimport { createToolset } from './toolset';\nimport { createViewSource } from './view-cache';\n\n/** The error sink: the option, `console.error` by default, never throwing. */\nexport function sinkOf(\n\toption: McpOptions['onError'],\n): (error: unknown) => void {\n\tif (option === false) return () => {};\n\tconst sink =\n\t\toption ??\n\t\t((error: unknown) => {\n\t\t\t// The SDK reports a client's protocol mistakes too (\"Rejected ...\"); they are not ours.\n\t\t\tif (error instanceof Error && error.message.startsWith('Rejected '))\n\t\t\t\treturn;\n\t\t\tconsole.error('[graxia/mcp] unexpected error', error);\n\t\t});\n\treturn (error) => {\n\t\ttry {\n\t\t\tsink(error);\n\t\t} catch {}\n\t};\n}\n\n/**\n * Creates an MCP server over a graxia instance: Streamable HTTP, stateless,\n * with the generic tools `graphql_schema`, `graphql_query` and (with\n * `mutations: true`) `graphql_mutate`. Every operation runs through\n * `graxia.execute`, so limits, cost, trusted documents, masking and rate\n * limits apply; the schema and the body limit come from `graxia`. With\n * `operations`, each persisted operation is also a typed tool. When graxia\n * runs trusted documents in `strict` mode, `graphql_query` and\n * `graphql_mutate` are not offered: only the typed tools run. Without\n * `auth` there is no authentication here: put the endpoint behind your own,\n * and use `can` for permissions. With `auth` it is an OAuth resource server\n * (bearer tokens, scopes, protected resource metadata), and `metadataPath`\n * is a string.\n *\n * @example\n * const mcp = createMcp(graxia, { name: 'library' });\n * Bun.serve({ routes: { '/mcp': (req, server) => mcp.fetch(req, { server }) }, fetch: graxia.fetch });\n */\nexport function createMcp<HostCtx extends object = Record<never, never>>(\n\tgraxia: McpHost<HostCtx>,\n\toptions: McpOptions<HostCtx> & { auth: McpAuthOptions },\n): Mcp<HostCtx> & { metadataPath: string };\nexport function createMcp<HostCtx extends object = Record<never, never>>(\n\tgraxia: McpHost<HostCtx>,\n\toptions: McpOptions<HostCtx>,\n): Mcp<HostCtx>;\nexport function createMcp<HostCtx extends object = Record<never, never>>(\n\tgraxia: McpHost<HostCtx>,\n\toptions: McpOptions<HostCtx>,\n): Mcp<HostCtx> {\n\tcheckOriginOptions(options.allowedHosts, options.allowedOrigins);\n\tconst onError = sinkOf(options.onError);\n\tconst settings: PipelineSettings = {\n\t\tallowedOrigins: options.allowedOrigins ?? [],\n\t\tallowedHosts: options.allowedHosts ?? defaultHosts(),\n\t\tmaxBody: graxia.limits.bodyBytes,\n\t};\n\tconst auth = options.auth ? resolveAuth(options.auth) : undefined;\n\tconst mutations = options.mutations ?? false;\n\tconst carrier = createContextCarrier();\n\tconst views = createViewSource(graxia.schema, options.can);\n\tconst toolset = createToolset(graxia, options, mutations, onError);\n\tconst handler = createMcpHandler(\n\t\tserverFactory({ graxia, options, auth, carrier, toolset, onError }),\n\t\t{\n\t\t\tmaxRequestBodySize: settings.maxBody,\n\t\t\tonerror: (error) => onError(error),\n\t\t},\n\t);\n\treturn {\n\t\tmetadataPath: auth?.metadataPath,\n\t\tmetadata: metadataHandler(auth, mutations),\n\t\tasync fetch(request, ...rest) {\n\t\t\tconst cors = corsOrigin(request, settings.allowedOrigins);\n\t\t\ttry {\n\t\t\t\tconst admitted = await admit(\n\t\t\t\t\trequest,\n\t\t\t\t\tsettings,\n\t\t\t\t\tauth && ((r) => authenticate(r, auth, onError)),\n\t\t\t\t);\n\t\t\t\tif (admitted instanceof Response) return withCors(admitted, cors);\n\t\t\t\tconst principal = admitted.gated;\n\t\t\t\tconst serverContext = (rest[0] ?? {}) as object;\n\t\t\t\tconst state = {\n\t\t\t\t\tserverContext,\n\t\t\t\t\tcalls: await toolCallsOf(admitted.request),\n\t\t\t\t\tview: views(admitted.request, serverContext, principal),\n\t\t\t\t};\n\t\t\t\t// With mutations off no scope opens a writing tool: the SDK answers tool-not-found.\n\t\t\t\tif (auth && principal && mutations) {\n\t\t\t\t\tconst stepUp = await writeStepUp(\n\t\t\t\t\t\tauth,\n\t\t\t\t\t\tprincipal,\n\t\t\t\t\t\tstate.calls.called,\n\t\t\t\t\t\t(name) => toolset.writes(name, state.view),\n\t\t\t\t\t);\n\t\t\t\t\tif (stepUp) return withCors(stepUp, cors);\n\t\t\t\t}\n\t\t\t\t// authInfo is not passed to the SDK (mcpAuth() carries the principal), so its tool scopeChallenge is unused.\n\t\t\t\tconst response = await carrier.run(state, () =>\n\t\t\t\t\trunAs(principal, () => handler.fetch(admitted.request)),\n\t\t\t\t);\n\t\t\t\treturn withCors(response, cors);\n\t\t\t} catch (error) {\n\t\t\t\tonError(error);\n\t\t\t\treturn withCors(\n\t\t\t\t\trefusal(\n\t\t\t\t\t\t500,\n\t\t\t\t\t\t'The MCP server failed to handle the request.',\n\t\t\t\t\t\t'Retry later; check the server logs.',\n\t\t\t\t\t),\n\t\t\t\t\tcors,\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\tdispose: () => handler.close(),\n\t};\n}\n",
|
|
7
|
+
"import type { McpErrorCode } from './codes';\n\n/** A JSON-RPC error response with a `fix`: what an MCP client gets when the request never reaches a tool. */\nexport function refusal(\n\tstatus: number,\n\tmessage: string,\n\tfix: string,\n\theaders: HeadersInit = {},\n\tcode?: McpErrorCode,\n): Response {\n\treturn Response.json(\n\t\t{\n\t\t\tjsonrpc: '2.0',\n\t\t\terror: {\n\t\t\t\tcode: -32000,\n\t\t\t\tmessage,\n\t\t\t\tdata: code === undefined ? { fix } : { code, fix },\n\t\t\t},\n\t\t\tid: null,\n\t\t},\n\t\t{ status, headers },\n\t);\n}\n",
|
|
8
|
+
"import { refusal } from '../refusal';\nimport type { McpAuthInfo, ResolvedAuth } from './types';\n\n/** `WWW-Authenticate: Bearer ...` with the metadata URL, per RFC 6750 and 9728. */\nexport function challenge(\n\tauth: ResolvedAuth,\n\tparams: { error?: string; description?: string; scope?: string },\n): string {\n\tconst parts: string[] = [];\n\tif (params.error) parts.push(`error=\"${params.error}\"`);\n\tif (params.description)\n\t\tparts.push(`error_description=\"${params.description}\"`);\n\tparts.push(`resource_metadata=\"${auth.metadataUrl}\"`);\n\tif (params.scope) parts.push(`scope=\"${params.scope}\"`);\n\treturn `Bearer ${parts.join(', ')}`;\n}\n\nconst bearerOf = (request: Request): string | undefined => {\n\tconst match = /^Bearer\\s+(\\S+)\\s*$/i.exec(\n\t\trequest.headers.get('authorization') ?? '',\n\t);\n\treturn match?.[1];\n};\n\n/** Compares resource identifiers ignoring a fragment and one trailing slash (RFC 8707). */\nconst sameResource = (a: string, b: string): boolean => {\n\tconst clean = (s: string) => s.replace(/#.*$/, '').replace(/\\/$/, '');\n\treturn clean(a) === clean(b);\n};\n\nconst unauthorized = (\n\tauth: ResolvedAuth,\n\tdescription: string,\n\tfix: string,\n): Response =>\n\trefusal(\n\t\t401,\n\t\t`Unauthorized: ${description}.`,\n\t\tfix,\n\t\t{\n\t\t\t'www-authenticate': challenge(auth, {\n\t\t\t\terror: 'invalid_token',\n\t\t\t\tdescription,\n\t\t\t}),\n\t\t},\n\t\t'MCP_UNAUTHORIZED',\n\t);\n\n/** The 503 of a verifier that threw: an outage is never a 401. */\nconst unavailable = (): Response =>\n\trefusal(\n\t\t503,\n\t\t'The access token could not be verified: the token verifier failed.',\n\t\t'Retry in a few seconds with the same token. If it persists, the server owner should read the error onError received. A verifier that throws for an invalid token must resolve undefined instead.',\n\t\t{ 'retry-after': '5' },\n\t);\n\n/** Seconds since the epoch stay under this for millennia; above it the value is milliseconds. */\nconst MAX_EXPIRES_AT = 1e11;\n\n/**\n * What the verifier's answer is refused for, if anything: a shape the\n * verifier got wrong (also sent to `onError`), an expired token, an audience\n * that is not this resource, a missing read scope.\n */\nfunction refusalOf(\n\tinfo: McpAuthInfo,\n\tauth: ResolvedAuth,\n\tonError: (error: unknown) => void,\n): Response | undefined {\n\tconst { resource } = auth.options;\n\tconst renew = `Get a new access token from the authorization server (see ${auth.metadataUrl}) and retry.`;\n\tconst owner = (what: string, fix: string) => {\n\t\tonError(new Error(`createMcp: ${what}. Fix: ${fix}`));\n\t\treturn 'Retry later; the server owner has to correct its token verifier (the error went to onError).';\n\t};\n\tif (!Array.isArray(info.scopes))\n\t\treturn unauthorized(\n\t\t\tauth,\n\t\t\t'the verifier returned no scopes',\n\t\t\towner(\n\t\t\t\t'verifyToken must return scopes',\n\t\t\t\t'return { scopes: [...] }, the list of scopes the token carries (an empty list for none).',\n\t\t\t),\n\t\t);\n\tconst { expiresAt } = info;\n\tif (expiresAt !== undefined) {\n\t\tif (!Number.isFinite(expiresAt) || expiresAt > MAX_EXPIRES_AT)\n\t\t\treturn unauthorized(\n\t\t\t\tauth,\n\t\t\t\t'the verifier returned an unusable expiry (expiresAt is in seconds)',\n\t\t\t\towner(\n\t\t\t\t\t`verifyToken returned expiresAt ${String(expiresAt)}, and expiresAt is in seconds since the epoch`,\n\t\t\t\t\t'return the exp claim as is, or Math.floor(date.getTime() / 1000); leave it out when the token has no expiry.',\n\t\t\t\t),\n\t\t\t);\n\t\tif (expiresAt <= Date.now() / 1000)\n\t\t\treturn unauthorized(auth, 'the access token has expired', renew);\n\t}\n\tif (auth.options.audience !== 'verifier') {\n\t\tconst forResource = `Get an access token issued for ${resource} (the \"resource\" parameter of the authorization and token requests, RFC 8707) and retry.`;\n\t\tif (info.audience === undefined)\n\t\t\treturn unauthorized(\n\t\t\t\tauth,\n\t\t\t\t'the access token carries no audience',\n\t\t\t\t`${forResource} Server owner: return audience from verifyToken, or set auth.audience to 'verifier' when the verifier checks it itself.`,\n\t\t\t);\n\t\tconst audiences =\n\t\t\ttypeof info.audience === 'string' ? [info.audience] : info.audience;\n\t\tif (!audiences.some((a) => sameResource(a, resource)))\n\t\t\treturn unauthorized(\n\t\t\t\tauth,\n\t\t\t\t'the access token was issued for another resource',\n\t\t\t\tforResource,\n\t\t\t);\n\t}\n\tif (!info.scopes.includes(auth.read))\n\t\treturn insufficient(auth, [auth.read], `the token lacks ${auth.read}`);\n\treturn undefined;\n}\n\n/**\n * The bearer gate: resolves the verified token's info, or the answer to send\n * instead (400 token in the query string, 401 missing or invalid token, 403\n * missing read scope, 503 failing verifier, or the verifier's own `Response`).\n * Runs before the body is read.\n */\nexport async function authenticate(\n\trequest: Request,\n\tauth: ResolvedAuth,\n\tonError: (error: unknown) => void,\n): Promise<McpAuthInfo | Response> {\n\tif (new URL(request.url).searchParams.has('access_token'))\n\t\treturn refusal(\n\t\t\t400,\n\t\t\t'The access token is in the query string.',\n\t\t\t'Send the token in the header Authorization: Bearer <token>; a token in a URL is refused.',\n\t\t\t{ 'www-authenticate': challenge(auth, { error: 'invalid_request' }) },\n\t\t\t'MCP_TOKEN_IN_URL',\n\t\t);\n\tconst token = bearerOf(request);\n\tif (token === undefined)\n\t\treturn refusal(\n\t\t\t401,\n\t\t\t'Unauthorized: no bearer token.',\n\t\t\t`Send Authorization: Bearer <token>. Fetch the authorization server from ${auth.metadataUrl}, get a token with the scope ${auth.read}, and retry.`,\n\t\t\t{ 'www-authenticate': challenge(auth, { scope: auth.read }) },\n\t\t\t'MCP_UNAUTHORIZED',\n\t\t);\n\tlet verified: McpAuthInfo | Response | undefined;\n\ttry {\n\t\tverified = await auth.options.verifyToken(token, request);\n\t} catch (error) {\n\t\tonError(error);\n\t\treturn unavailable();\n\t}\n\tif (verified instanceof Response) return verified;\n\tif (verified === undefined || verified === null)\n\t\treturn unauthorized(\n\t\t\tauth,\n\t\t\t'the access token is invalid',\n\t\t\t`Get a new access token from the authorization server (see ${auth.metadataUrl}) and retry.`,\n\t\t);\n\treturn refusalOf(verified, auth, onError) ?? verified;\n}\n\n/** The 403 `insufficient_scope` answer, naming the full scope set the token needs. */\nexport function insufficient(\n\tauth: ResolvedAuth,\n\tscopes: readonly string[],\n\tdescription: string,\n): Response {\n\tconst scope = scopes.join(' ');\n\treturn refusal(\n\t\t403,\n\t\t`Forbidden: ${description}.`,\n\t\t`Ask the authorization server for a token with the scope${scopes.length > 1 ? 's' : ''} \"${scope}\" (see ${auth.metadataUrl}), then retry.`,\n\t\t{\n\t\t\t'www-authenticate': challenge(auth, {\n\t\t\t\terror: 'insufficient_scope',\n\t\t\t\tdescription,\n\t\t\t\tscope,\n\t\t\t}),\n\t\t},\n\t\t'MCP_INSUFFICIENT_SCOPE',\n\t);\n}\n",
|
|
9
|
+
"import type { ResolvedAuth } from './types';\n\nconst CORS = { 'access-control-allow-origin': '*' };\n\n/**\n * The RFC 9728 protected resource metadata handler: GET only, CORS `*`,\n * cached an hour. The write scope is published only when `mutations` is on:\n * without it no tool needs that scope.\n */\nexport function metadataHandler(\n\tauth: ResolvedAuth | undefined,\n\tmutations: boolean,\n): (request: Request) => Response {\n\tif (auth === undefined) return () => new Response(null, { status: 404 });\n\tconst { options } = auth;\n\tconst body = JSON.stringify({\n\t\tresource: options.resource,\n\t\tauthorization_servers: options.authorizationServers,\n\t\tscopes_supported: mutations ? [auth.read, auth.write] : [auth.read],\n\t\tbearer_methods_supported: ['header'],\n\t\t...(options.resourceName !== undefined && {\n\t\t\tresource_name: options.resourceName,\n\t\t}),\n\t\t...(options.documentation !== undefined && {\n\t\t\tresource_documentation: options.documentation,\n\t\t}),\n\t});\n\treturn (request) => {\n\t\tif (request.method === 'OPTIONS')\n\t\t\treturn new Response(null, {\n\t\t\t\tstatus: 204,\n\t\t\t\theaders: {\n\t\t\t\t\t...CORS,\n\t\t\t\t\t'access-control-allow-methods': 'GET',\n\t\t\t\t\t'access-control-max-age': '3600',\n\t\t\t\t},\n\t\t\t});\n\t\tif (request.method !== 'GET' && request.method !== 'HEAD')\n\t\t\treturn new Response(null, {\n\t\t\t\tstatus: 405,\n\t\t\t\theaders: { ...CORS, allow: 'GET, HEAD, OPTIONS' },\n\t\t\t});\n\t\treturn new Response(request.method === 'HEAD' ? null : body, {\n\t\t\theaders: {\n\t\t\t\t...CORS,\n\t\t\t\t'content-type': 'application/json',\n\t\t\t\t'cache-control': 'max-age=3600',\n\t\t\t},\n\t\t});\n\t};\n}\n",
|
|
10
|
+
"import { GraxiaConfigError } from '@graxia/core';\nimport { getOAuthProtectedResourceMetadataUrl } from '@modelcontextprotocol/server';\nimport type { McpAuthOptions, ResolvedAuth } from './types';\n\n/** Validates `auth` once, at `createMcp`, and derives what every request needs. */\nexport function resolveAuth(options: McpAuthOptions): ResolvedAuth {\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(options.resource);\n\t} catch {\n\t\tthrow new GraxiaConfigError(\n\t\t\t`createMcp: auth.resource must be an absolute URL (got \"${options.resource}\"). Fix: pass the public URL of the MCP endpoint, e.g. https://api.example.com/mcp.`,\n\t\t);\n\t}\n\tif (url.hash !== '' || url.search !== '' || /[?#]$/.test(options.resource))\n\t\tthrow new GraxiaConfigError(\n\t\t\t`createMcp: auth.resource must have no query and no fragment (got \"${options.resource}\"). Fix: pass the URL of the MCP endpoint alone, e.g. ${url.origin}${url.pathname}.`,\n\t\t);\n\tif (options.authorizationServers.length === 0)\n\t\tthrow new GraxiaConfigError(\n\t\t\t'createMcp: auth.authorizationServers is empty. Fix: list the issuer URL of the authorization server that issues the tokens.',\n\t\t);\n\tfor (const server of options.authorizationServers)\n\t\tif (!URL.canParse(server))\n\t\t\tthrow new GraxiaConfigError(\n\t\t\t\t`createMcp: auth.authorizationServers must hold absolute URLs (got \"${server}\"). Fix: pass the issuer URL of the authorization server, e.g. https://auth.example.com.`,\n\t\t\t);\n\tconst metadataUrl = getOAuthProtectedResourceMetadataUrl(url);\n\treturn {\n\t\toptions,\n\t\tread: options.scopes?.read ?? 'mcp:read',\n\t\twrite: options.scopes?.write ?? 'mcp:write',\n\t\tmetadataUrl,\n\t\tmetadataPath: new URL(metadataUrl).pathname,\n\t};\n}\n",
|
|
11
|
+
"import { insufficient } from './bearer';\nimport type { McpAuthInfo, ResolvedAuth } from './types';\n\n/** Whether the token may call the tools that write (`graphql_mutate`, a mutation's typed tool). */\nexport const canWrite = (auth: ResolvedAuth, info: McpAuthInfo): boolean =>\n\tinfo.scopes.includes(auth.write);\n\n/**\n * Step-up: a read-only token that calls a tool that writes (`graphql_mutate`\n * or a mutation's typed tool, from a stale tool list) gets the 403\n * `insufficient_scope` naming `read write`, so a client can re-authorize.\n * `writes` says whether the write scope would open the tool to this caller:\n * a tool the caller's view hides gets no 403, so it answers like an unknown\n * one. Only when the server has mutations on: otherwise no scope would help,\n * and the call gets the SDK's tool-not-found.\n */\nexport async function writeStepUp(\n\tauth: ResolvedAuth,\n\tinfo: McpAuthInfo,\n\tcalled: readonly string[],\n\twrites: (name: string) => Promise<boolean>,\n): Promise<Response | undefined> {\n\tif (canWrite(auth, info)) return undefined;\n\tfor (const name of called)\n\t\tif (await writes(name))\n\t\t\treturn insufficient(\n\t\t\t\tauth,\n\t\t\t\t[auth.read, auth.write],\n\t\t\t\t`${name} needs the scope ${auth.write}`,\n\t\t\t);\n\treturn undefined;\n}\n",
|
|
12
|
+
"/** What the JSON-RPC body of a request asks of the tools. */\nexport interface ToolCalls {\n\t/** It holds a `tools/list`. */\n\tlist: boolean;\n\t/** The names of its `tools/call` messages. */\n\tcalled: readonly string[];\n}\n\n/**\n * Reads what a request asks of the tools (a message or a batch), from a copy\n * of its body: call it on the admitted request, whose body is in memory. A\n * body that is not JSON asks nothing; the SDK refuses it.\n */\nexport async function toolCallsOf(request: Request): Promise<ToolCalls> {\n\tlet body: unknown;\n\ttry {\n\t\tbody = JSON.parse(await request.clone().text());\n\t} catch {\n\t\treturn { list: false, called: [] };\n\t}\n\tlet list = false;\n\tconst called: string[] = [];\n\tfor (const message of Array.isArray(body) ? body : [body]) {\n\t\tif (typeof message !== 'object' || message === null) continue;\n\t\tconst { method, params } = message as {\n\t\t\tmethod?: unknown;\n\t\t\tparams?: { name?: unknown } | null;\n\t\t};\n\t\tif (method === 'tools/list') list = true;\n\t\tif (method === 'tools/call' && typeof params?.name === 'string')\n\t\t\tcalled.push(params.name);\n\t}\n\treturn { list, called };\n}\n",
|
|
13
|
+
"import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { ToolCalls } from './calls';\nimport type { View } from './view';\n\n/** What `fetch` knows about one request, for the SDK's per-request factory. */\nexport interface RequestState {\n\t/** The `serverContext` given to `fetch`. */\n\tserverContext: object;\n\t/** What the body asks of the tools. */\n\tcalls: ToolCalls;\n\t/** The caller's view, built on first use and once. */\n\tview: () => Promise<View>;\n}\n\n/** Carries a request's state from `fetch` to the SDK's per-request factory. */\nexport interface ContextCarrier {\n\t/** Runs `fn` with `state` as the current one. */\n\trun<T>(state: RequestState, fn: () => T): T;\n\t/** The state of the request being handled; throws outside `run`. */\n\tcurrent(): RequestState;\n}\n\nexport function createContextCarrier(): ContextCarrier {\n\tconst storage = new AsyncLocalStorage<RequestState>();\n\treturn {\n\t\trun: (state, fn) => storage.run(state, fn),\n\t\tcurrent() {\n\t\t\tconst store = storage.getStore();\n\t\t\tif (store === undefined)\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'createMcp: no serverContext for this request; the MCP handler ran outside fetch.',\n\t\t\t\t);\n\t\t\treturn store;\n\t\t},\n\t};\n}\n",
|
|
14
|
+
"const ALLOW_HEADERS =\n\t'content-type, authorization, mcp-protocol-version, mcp-session-id, mcp-method, mcp-name, last-event-id, accept';\n\n/** The origin to echo in `Access-Control-Allow-Origin`: the request's, when `allowed` lists it. */\nexport function corsOrigin(\n\trequest: Request,\n\tallowed: readonly string[],\n): string | undefined {\n\tconst origin = request.headers.get('origin');\n\treturn origin !== null && allowed.includes(origin) ? origin : undefined;\n}\n\n/** The answer to a preflight from an allowed origin. */\nexport function preflight(origin: string, requested?: string | null): Response {\n\treturn new Response(null, {\n\t\tstatus: 204,\n\t\theaders: {\n\t\t\t'access-control-allow-origin': origin,\n\t\t\t'access-control-allow-methods': 'POST',\n\t\t\t'access-control-allow-headers': requested\n\t\t\t\t? `${ALLOW_HEADERS}, ${requested}`\n\t\t\t\t: ALLOW_HEADERS,\n\t\t\t'access-control-max-age': '600',\n\t\t\tvary: 'Origin',\n\t\t},\n\t});\n}\n\n/** `response` with the CORS headers of an allowed origin (unchanged when `origin` is undefined). */\nexport function withCors(\n\tresponse: Response,\n\torigin: string | undefined,\n): Response {\n\tif (\n\t\torigin === undefined ||\n\t\tresponse.headers.has('access-control-allow-origin')\n\t)\n\t\treturn response;\n\tconst headers = new Headers(response.headers);\n\theaders.set('access-control-allow-origin', origin);\n\theaders.set(\n\t\t'access-control-expose-headers',\n\t\t'mcp-protocol-version, www-authenticate',\n\t);\n\theaders.append('vary', 'Origin');\n\treturn new Response(response.body, {\n\t\tstatus: response.status,\n\t\tstatusText: response.statusText,\n\t\theaders,\n\t});\n}\n",
|
|
15
|
+
"import {\n\tlocalhostAllowedHostnames,\n\tvalidateHostHeader,\n} from '@modelcontextprotocol/server';\nimport { refusal } from './refusal';\n\n/** The allow-lists of the DNS-rebinding guard. */\nexport interface OriginPolicy {\n\tallowedOrigins: readonly string[];\n\t/** Hostnames without port; IPv6 in brackets. */\n\tallowedHosts: readonly string[];\n}\n\n/** The hostnames allowed by default: the local ones. */\nexport const defaultHosts = (): string[] => localhostAllowedHostnames();\n\n/**\n * The DNS-rebinding guard of the MCP spec. A request that carries an\n * `Origin` passes only if the origin is in `allowedOrigins`, or it is the\n * endpoint's own origin and the `Host` header names an `allowedHosts`\n * hostname (an attacker's rebound domain is same-origin with itself, and\n * fails there). No `Origin` (a server, a CLI) passes. Returns the refusal,\n * or `undefined`.\n */\nexport function checkOrigin(\n\trequest: Request,\n\tpolicy: OriginPolicy,\n): Response | undefined {\n\tconst origin = request.headers.get('origin');\n\tif (origin === null || policy.allowedOrigins.includes(origin))\n\t\treturn undefined;\n\tconst url = new URL(request.url);\n\tif (origin !== url.origin)\n\t\treturn refusal(\n\t\t\t403,\n\t\t\t`Origin ${origin} is not allowed.`,\n\t\t\t`Add ${JSON.stringify(origin)} to createMcp's allowedOrigins, or call the endpoint without a browser Origin.`,\n\t\t);\n\tconst host = request.headers.get('host') ?? url.host;\n\tconst checked = validateHostHeader(host, [...policy.allowedHosts]);\n\tif (checked.ok) return undefined;\n\treturn refusal(\n\t\t403,\n\t\t`Host ${host} is not allowed.`,\n\t\t`Add ${JSON.stringify(checked.hostname ?? host)} to createMcp's allowedHosts (hostnames without port). Behind a proxy, list the public hostname.`,\n\t);\n}\n",
|
|
16
|
+
"import { GraxiaConfigError } from '@graxia/core';\n\n/** The hostname an `allowedHosts` entry should be, or `undefined` when it is already one. */\nfunction hostnameOf(entry: string): string | undefined {\n\tif (/^[a-z][a-z0-9+.-]*:\\/\\//i.test(entry)) {\n\t\tconst url = URL.parse(entry);\n\t\treturn url\n\t\t\t? url.hostname\n\t\t\t: entry.replace(/^[^/]*\\/\\//, '').split(/[/:]/)[0];\n\t}\n\tif (entry.includes('/')) return entry.split('/')[0]?.replace(/:\\d+$/, '');\n\tif (/^\\[.*\\](:\\d+)$/.test(entry)) return entry.replace(/:\\d+$/, '');\n\tif (\n\t\t!entry.startsWith('[') &&\n\t\tentry.split(':').length === 2 &&\n\t\t/:\\d+$/.test(entry)\n\t)\n\t\treturn entry.replace(/:\\d+$/, '');\n\treturn undefined;\n}\n\n/** The exact origin an `allowedOrigins` entry should be, or `undefined` when it is already one. */\nfunction originOf(entry: string): string | undefined {\n\tconst url = URL.parse(entry);\n\tif (!url || url.origin === 'null') return undefined;\n\treturn url.origin === entry ? undefined : url.origin;\n}\n\n/**\n * Checks `allowedHosts` and `allowedOrigins` once, at `createMcp`: an entry\n * the request check could never match (a host with a port, a scheme or a\n * path; an origin with a trailing slash or a path) would only show up as a\n * 403 on every browser call.\n * @throws {GraxiaConfigError} naming the entry and the corrected value.\n */\nexport function checkOriginOptions(\n\tallowedHosts: readonly string[] | undefined,\n\tallowedOrigins: readonly string[] | undefined,\n): void {\n\tfor (const entry of allowedHosts ?? []) {\n\t\tconst fixed = hostnameOf(entry);\n\t\tif (fixed !== undefined)\n\t\t\tthrow new GraxiaConfigError(\n\t\t\t\t`createMcp: allowedHosts entry \"${entry}\" can never match: it is a hostname without scheme, port or path. Fix: use \"${fixed}\".`,\n\t\t\t);\n\t}\n\tfor (const entry of allowedOrigins ?? []) {\n\t\tconst fixed = originOf(entry);\n\t\tif (fixed !== undefined)\n\t\t\tthrow new GraxiaConfigError(\n\t\t\t\t`createMcp: allowedOrigins entry \"${entry}\" can never match: an origin is exactly scheme://host[:port], no path and no trailing slash. Fix: use \"${fixed}\".`,\n\t\t\t);\n\t\tif (!URL.canParse(entry))\n\t\t\tthrow new GraxiaConfigError(\n\t\t\t\t`createMcp: allowedOrigins entry \"${entry}\" is not an origin. Fix: use scheme://host[:port], e.g. \"https://app.example\".`,\n\t\t\t);\n\t}\n}\n",
|
|
17
|
+
"import { refusal } from './refusal';\n\nconst TOO_LARGE = (max: number) =>\n\trefusal(\n\t\t413,\n\t\t`The request body is larger than ${max} bytes.`,\n\t\t'Send a smaller request, or raise limits.bodyBytes of the graxia instance (this endpoint enforces the same).',\n\t);\n\n/**\n * Reads a POST body under `max` bytes. Returns a copy of the request whose\n * body is already in memory, or the 413 / 415 refusal.\n */\nexport async function boundedRequest(\n\trequest: Request,\n\tmax: number,\n): Promise<Request | Response> {\n\tconst type = request.headers.get('content-type') ?? '';\n\tif (!/^application\\/json\\s*(;|$)/i.test(type))\n\t\treturn refusal(\n\t\t\t415,\n\t\t\t'The request body must be application/json.',\n\t\t\t'Send the JSON-RPC message with the header Content-Type: application/json.',\n\t\t);\n\tconst declared = Number(request.headers.get('content-length'));\n\tif (declared > max) return TOO_LARGE(max);\n\tconst chunks: Uint8Array[] = [];\n\tlet size = 0;\n\tif (request.body) {\n\t\tfor await (const chunk of request.body) {\n\t\t\tsize += chunk.byteLength;\n\t\t\tif (size > max) return TOO_LARGE(max);\n\t\t\tchunks.push(chunk);\n\t\t}\n\t}\n\tconst bytes = new Uint8Array(size);\n\tlet at = 0;\n\tfor (const chunk of chunks) {\n\t\tbytes.set(chunk, at);\n\t\tat += chunk.byteLength;\n\t}\n\treturn new Request(request.url, {\n\t\tmethod: request.method,\n\t\theaders: request.headers,\n\t\tbody: bytes,\n\t\tsignal: request.signal,\n\t});\n}\n",
|
|
18
|
+
"import { boundedRequest } from './body';\nimport { corsOrigin, preflight } from './cors';\nimport { checkOrigin, type OriginPolicy } from './origin';\nimport { refusal } from './refusal';\n\n/** What the HTTP checks need. */\nexport interface PipelineSettings extends OriginPolicy {\n\tmaxBody: number;\n}\n\n/**\n * The HTTP checks before the MCP handler, in order: origin and host (403),\n * CORS preflight, method (405), the optional `gate` (authentication, before\n * the body is read), content type (415) and body size (413). Resolves the\n * refusal, or a copy of the request whose body is read with the gate's result.\n */\nexport async function admit<T = undefined>(\n\trequest: Request,\n\tsettings: PipelineSettings,\n\tgate?: (request: Request) => Promise<T | Response>,\n): Promise<Response | { request: Request; gated: T | undefined }> {\n\tconst forbidden = checkOrigin(request, settings);\n\tif (forbidden) return forbidden;\n\tconst cors = corsOrigin(request, settings.allowedOrigins);\n\tif (request.method === 'OPTIONS' && cors !== undefined)\n\t\treturn preflight(\n\t\t\tcors,\n\t\t\trequest.headers.get('access-control-request-headers'),\n\t\t);\n\tif (request.method !== 'POST')\n\t\treturn refusal(\n\t\t\t405,\n\t\t\t`${request.method} is not supported: this endpoint is stateless.`,\n\t\t\t'Send the JSON-RPC message with POST. There is no server-initiated stream to open or session to close.',\n\t\t\t{ allow: 'POST' },\n\t\t);\n\tconst gated = gate ? await gate(request) : undefined;\n\tif (gated instanceof Response) return gated;\n\tconst bounded = await boundedRequest(request, settings.maxBody);\n\treturn bounded instanceof Response ? bounded : { request: bounded, gated };\n}\n",
|
|
19
|
+
"import { McpServer, type McpServerFactory } from '@modelcontextprotocol/server';\nimport { mcpAuth } from './auth/principal';\nimport { canWrite } from './auth/scopes';\nimport type { ResolvedAuth } from './auth/types';\nimport type { ContextCarrier, RequestState } from './context';\nimport {\n\tregisterFailedTools,\n\tregisterOperationTools,\n} from './operations/register';\nimport type { OperationTool } from './operations/types';\nimport type { McpHost, McpOptions } from './options';\nimport { registerTools } from './tools';\nimport type { ExecuteContext } from './tools/execute';\nimport type { Toolset } from './toolset';\n\n/** The per-request pieces a tool call needs, once the request is known. */\nexport type RequestContext = Pick<\n\tExecuteContext,\n\t| 'graxia'\n\t| 'view'\n\t| 'serverContext'\n\t| 'headers'\n\t| 'signal'\n\t| 'writeScope'\n\t| 'onError'\n>;\n\n/** Headers that describe the MCP exchange, not the caller: they are not forwarded to `context`. */\nconst OWN_HEADERS =\n\t/^(content-type|content-length|accept|host|origin|connection|transfer-encoding|mcp-.*)$/i;\n\n/** The headers `graxia.execute` sees: the caller's (an `Authorization`, a session cookie), minus the transport's. */\nexport function forwardedHeaders(request: Request): Headers {\n\tconst headers = new Headers();\n\tfor (const [name, value] of request.headers)\n\t\tif (!OWN_HEADERS.test(name)) headers.set(name, value);\n\treturn headers;\n}\n\n/** What {@link serverFactory} builds every request's server from. */\nexport interface ServerSettings {\n\tgraxia: McpHost<any>;\n\toptions: McpOptions<any>;\n\tauth: ResolvedAuth | undefined;\n\tcarrier: ContextCarrier;\n\ttoolset: Toolset;\n\tonError: (error: unknown) => void;\n}\n\n/** The typed tools of one caller: `offered`, or `failed` when the view did not build. */\ninterface Typed {\n\toffered: readonly OperationTool[];\n\tfailed: readonly OperationTool[];\n}\n\n/**\n * The typed tools the caller's view allows. The view is built (and `can`\n * run) only for a request that lists or calls tools: `initialize`, `ping`\n * and notifications never pay for it. When it fails to build, nothing is\n * offered; a request that only calls gets the known names as failing tools.\n */\nasync function typedFor(\n\tsettings: ServerSettings,\n\tstate: RequestState,\n\tmutations: boolean,\n): Promise<Typed> {\n\tconst { toolset, onError } = settings;\n\tconst { list, called } = state.calls;\n\tif (toolset.typed.length === 0 || !(list || called.length > 0))\n\t\treturn { offered: [], failed: [] };\n\tconst mine = (tool: OperationTool) => mutations || tool.kind === 'query';\n\ttry {\n\t\tconst visible = toolset.visible(await state.view());\n\t\treturn { offered: visible.filter(mine), failed: [] };\n\t} catch (error) {\n\t\tonError(error);\n\t\treturn { offered: [], failed: list ? [] : toolset.typed.filter(mine) };\n\t}\n}\n\n/**\n * The SDK's per-request factory: the stateless server of one caller, from\n * the state and the principal `fetch` put in their stores. `graphql_mutate`\n * and the typed tools of mutations are registered when `mutations` is on\n * and, with `auth`, the token has the write scope. A typed tool is\n * registered only when the caller's view allows its operation.\n */\nexport function serverFactory(settings: ServerSettings): McpServerFactory {\n\tconst { graxia, options, auth, carrier, toolset, onError } = settings;\n\treturn async ({ requestInfo }) => {\n\t\tconst request = requestInfo as Request;\n\t\tconst state = carrier.current();\n\t\tconst principal = mcpAuth();\n\t\tconst mutations =\n\t\t\t(options.mutations ?? false) &&\n\t\t\t(auth === undefined ||\n\t\t\t\t(principal !== undefined && canWrite(auth, principal)));\n\t\tconst typed = await typedFor(settings, state, mutations);\n\t\tconst context: RequestContext = {\n\t\t\tgraxia,\n\t\t\tview: state.view,\n\t\t\tserverContext: state.serverContext,\n\t\t\theaders: forwardedHeaders(request),\n\t\t\tsignal: request.signal,\n\t\t\twriteScope: auth?.write,\n\t\t\tonError,\n\t\t};\n\t\tconst server = new McpServer(\n\t\t\t{ name: options.name, version: options.version ?? '0.0.0' },\n\t\t\toptions.instructions ? { instructions: options.instructions } : undefined,\n\t\t);\n\t\tregisterTools(server, {\n\t\t\tcontext,\n\t\t\tmutations,\n\t\t\tgeneric: toolset.generic,\n\t\t\tlisting: state.calls.list,\n\t\t\ttyped: typed.offered.map((tool) => tool.name),\n\t\t});\n\t\tregisterOperationTools(server, typed.offered, context);\n\t\tregisterFailedTools(server, typed.failed);\n\t\treturn server;\n\t};\n}\n",
|
|
20
|
+
"import { GraxiaExecuteError } from '@graxia/core';\nimport type { CallToolResult } from '@modelcontextprotocol/server';\nimport { validate } from 'graphql';\nimport type { McpHost } from '../options';\nimport type { View } from '../view';\nimport {\n\ttype Allowed,\n\tcheckOperations,\n\tINTROSPECTION_FIX,\n\tparseOperation,\n\tVIEW_RULES,\n} from './operation';\nimport { type JsonResult, refused, resultOf } from './result';\n\n/** The input of `graphql_query` and `graphql_mutate`. */\nexport interface OperationInput {\n\tquery: string;\n\tvariables?: Record<string, unknown> | undefined;\n\toperationName?: string | undefined;\n}\n\n/** What one call runs against. */\nexport interface ExecuteContext {\n\tgraxia: McpHost<any>;\n\t/** The caller's view, built on first use. */\n\tview: () => Promise<View>;\n\tserverContext: object;\n\theaders: Headers;\n\tsignal?: AbortSignal | undefined;\n\t/** The scope `graphql_mutate` needs, when `auth` is on: named in the fix of a mutation sent to `graphql_query`. */\n\twriteScope?: string | undefined;\n\t/** Receives an unexpected failure with its cause. */\n\tonError: (error: unknown) => void;\n}\n\nconst SCHEMA_FIX =\n\t'Call graphql_schema (with { types: [...] } or { search }) to see the fields and arguments you may use, then correct the operation.';\n\nconst plain = (value: unknown): JsonResult =>\n\tJSON.parse(JSON.stringify(value)) as JsonResult;\n\n/** The errors graxia's own response carries (a plugin's `respond`, a refusal), so the agent keeps their code and fix. */\nasync function errorsOf(error: GraxiaExecuteError): Promise<CallToolResult> {\n\ttry {\n\t\tconst body = (await error.response.clone().json()) as JsonResult;\n\t\tif (Array.isArray(body?.errors) && body.errors.length > 0)\n\t\t\treturn resultOf({ errors: body.errors });\n\t} catch {}\n\treturn refused(\n\t\terror.message,\n\t\t'MCP_EXECUTION_REFUSED',\n\t\t'Retry later; if it persists, the server is shutting down or a plugin refused the request.',\n\t);\n}\n\n/** Runs one operation of the tool's `kind` through `graxia.execute`, after checking it against the caller's view. */\nexport async function runOperation(\n\tkind: Allowed,\n\tinput: OperationInput,\n\tcontext: ExecuteContext,\n): Promise<CallToolResult> {\n\tconst parsed = parseOperation(input.query, context.graxia.limits.tokens);\n\tif ('refusal' in parsed)\n\t\treturn refused(\n\t\t\tparsed.refusal.message,\n\t\t\tparsed.refusal.code,\n\t\t\tparsed.refusal.fix,\n\t\t);\n\tconst { document } = parsed;\n\tconst refusal = checkOperations(\n\t\tdocument,\n\t\tkind,\n\t\tinput.operationName,\n\t\tcontext.writeScope,\n\t);\n\tif (refusal) return refused(refusal.message, refusal.code, refusal.fix);\n\tconst problems = validate(\n\t\t(await context.view()).schema,\n\t\tdocument,\n\t\tVIEW_RULES,\n\t);\n\tif (problems.length > 0)\n\t\treturn resultOf({\n\t\t\terrors: problems.map((error) => ({\n\t\t\t\t...plain(error),\n\t\t\t\textensions: {\n\t\t\t\t\tcode: 'GRAPHQL_VALIDATION_FAILED',\n\t\t\t\t\tfix: /introspection/i.test(error.message)\n\t\t\t\t\t\t? INTROSPECTION_FIX\n\t\t\t\t\t\t: SCHEMA_FIX,\n\t\t\t\t},\n\t\t\t})),\n\t\t});\n\treturn execute(context, {\n\t\tdocument: input.query,\n\t\tvariables: input.variables,\n\t\toperationName: input.operationName,\n\t});\n}\n\n/** Runs a document through `graxia.execute` with the caller's headers and `serverContext`; graxia's refusals keep their code and fix. */\nexport async function execute(\n\tcontext: ExecuteContext,\n\toperation: {\n\t\tdocument: string;\n\t\tvariables?: Record<string, unknown> | undefined;\n\t\toperationName?: string | undefined;\n\t},\n): Promise<CallToolResult> {\n\ttry {\n\t\tconst result = await context.graxia.execute({\n\t\t\tdocument: operation.document,\n\t\t\t...(operation.variables ? { variables: operation.variables } : {}),\n\t\t\t...(operation.operationName\n\t\t\t\t? { operationName: operation.operationName }\n\t\t\t\t: {}),\n\t\t\theaders: context.headers,\n\t\t\t...(context.signal ? { signal: context.signal } : {}),\n\t\t\tserverContext: context.serverContext,\n\t\t});\n\t\treturn resultOf(plain(result));\n\t} catch (error) {\n\t\tif (error instanceof GraxiaExecuteError) return errorsOf(error);\n\t\tthrow error;\n\t}\n}\n",
|
|
21
|
+
"import {\n\ttype DocumentNode,\n\tFieldsOnCorrectTypeRule,\n\tKind,\n\tKnownArgumentNamesRule,\n\tKnownTypeNamesRule,\n\tNoSchemaIntrospectionCustomRule,\n\ttype OperationDefinitionNode,\n\tPossibleFragmentSpreadsRule,\n\tparse,\n\tvisit,\n} from 'graphql';\n\nexport type Allowed = 'query' | 'mutation';\n\n/** The first `@defer` or `@stream` the document uses, without the `@`. */\nexport function incrementalDirective(\n\tdocument: DocumentNode,\n): string | undefined {\n\tlet found: string | undefined;\n\tvisit(document, {\n\t\tDirective(node) {\n\t\t\tif (node.name.value === 'defer' || node.name.value === 'stream')\n\t\t\t\tfound ??= node.name.value;\n\t\t},\n\t});\n\treturn found;\n}\n\n/** A reason the document may not run here, as the message, code and fix an agent reads. */\nexport interface Refusal {\n\tmessage: string;\n\tcode: string;\n\tfix: string;\n}\n\n/**\n * The validation rules MCP applies to the caller's view: only the ones that\n * decide what the caller may see. Limits, cost and the rest of validation are\n * graxia's, when the operation runs.\n */\nexport const VIEW_RULES = [\n\tFieldsOnCorrectTypeRule,\n\tKnownTypeNamesRule,\n\tKnownArgumentNamesRule,\n\tPossibleFragmentSpreadsRule,\n\tNoSchemaIntrospectionCustomRule,\n] as const;\n\n/** The fix of an introspection refusal: the view is read through `graphql_schema`. */\nexport const INTROSPECTION_FIX = 'Use graphql_schema to read the schema.';\n\n/**\n * Parses `query` under graxia's token limit. A document that does not parse\n * is refused here (fail closed): `graxia.execute` is never reached, so a\n * lenient plugin parser cannot run what the MCP checks have not seen.\n */\nexport function parseOperation(\n\tquery: string,\n\ttokens: number | false,\n): { document: DocumentNode } | { refusal: Refusal } {\n\ttry {\n\t\treturn {\n\t\t\tdocument: parse(query, tokens === false ? {} : { maxTokens: tokens }),\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconst overflow = /more than \\d+ tokens/.test(message);\n\t\treturn {\n\t\t\trefusal: {\n\t\t\t\tmessage,\n\t\t\t\tcode: 'GRAPHQL_PARSE_FAILED',\n\t\t\t\tfix: overflow\n\t\t\t\t\t? 'Split the operation or raise limits.tokens.'\n\t\t\t\t\t: 'Correct the syntax of the document at the position the error points to.',\n\t\t\t},\n\t\t};\n\t}\n}\n\nconst wrongKind = (\n\tallowed: Allowed,\n\tfound: string,\n\twriteScope?: string,\n): Refusal => {\n\tif (found === 'subscription')\n\t\treturn {\n\t\t\tmessage: 'Subscriptions are not available over MCP.',\n\t\t\tcode: 'SUBSCRIPTION_NOT_SUPPORTED',\n\t\t\tfix: 'Send a query (graphql_query), or poll the same query again.',\n\t\t};\n\treturn {\n\t\tmessage: `A ${found} cannot run in graphql_${allowed === 'query' ? 'query' : 'mutate'}.`,\n\t\tcode: 'MCP_OPERATION_NOT_ALLOWED',\n\t\tfix:\n\t\t\tfound === 'mutation'\n\t\t\t\t? `Use graphql_mutate for mutations (it is listed only when the server enables mutations${writeScope ? ` and the token has the scope ${writeScope}` : ''}).`\n\t\t\t\t: 'Use graphql_query for queries.',\n\t};\n};\n\n/** The operation `operationName` picks, or the only one; `undefined` when the choice is ambiguous (graxia then refuses). */\nfunction selected(\n\tdocument: DocumentNode,\n\toperationName: string | undefined,\n): OperationDefinitionNode | undefined {\n\tconst operations = document.definitions.filter(\n\t\t(definition): definition is OperationDefinitionNode =>\n\t\t\tdefinition.kind === Kind.OPERATION_DEFINITION,\n\t);\n\tif (operationName)\n\t\treturn operations.find((o) => o.name?.value === operationName);\n\treturn operations.length === 1 ? operations[0] : undefined;\n}\n\n/**\n * Refuses what MCP does not run: the selected operation when it is another\n * kind than the tool's, and `@defer` / `@stream` (the result is one JSON value).\n * `writeScope` is the scope `graphql_mutate` needs when `auth` is on, for the fix.\n */\nexport function checkOperations(\n\tdocument: DocumentNode,\n\tallowed: Allowed,\n\toperationName?: string,\n\twriteScope?: string,\n): Refusal | undefined {\n\tconst operation = selected(document, operationName);\n\tif (operation && operation.operation !== allowed)\n\t\treturn wrongKind(allowed, operation.operation, writeScope);\n\tconst incremental = incrementalDirective(document);\n\tif (incremental)\n\t\treturn {\n\t\t\tmessage: `@${incremental} is not available over MCP.`,\n\t\t\tcode: 'INCREMENTAL_NOT_SUPPORTED',\n\t\t\tfix: `Remove @${incremental}: the tool returns one complete JSON result.`,\n\t\t};\n\treturn undefined;\n}\n",
|
|
22
|
+
"import type { CallToolResult } from '@modelcontextprotocol/server';\n\n/** A GraphQL-shaped result, as plain JSON. */\nexport interface JsonResult {\n\tdata?: unknown;\n\terrors?: readonly Record<string, unknown>[];\n}\n\n/** A tool result carrying a GraphQL result: `structuredContent` and its JSON as text; an error when there is no `data`. */\nexport function resultOf(result: JsonResult): CallToolResult {\n\treturn {\n\t\tcontent: [{ type: 'text', text: JSON.stringify(result) }],\n\t\tstructuredContent: result as Record<string, unknown>,\n\t\t...(result.data == null ? { isError: true } : {}),\n\t};\n}\n\n/** A refused call, shaped like a GraphQL error (`extensions.code` and `extensions.fix`) so agents read it the same way. */\nexport function refused(\n\tmessage: string,\n\tcode: string,\n\tfix: string,\n): CallToolResult {\n\treturn resultOf({ errors: [{ message, extensions: { code, fix } }] });\n}\n\n/** A plain text answer (the schema tool). */\nexport const textResult = (text: string, isError = false): CallToolResult => ({\n\tcontent: [{ type: 'text', text }],\n\t...(isError ? { isError: true } : {}),\n});\n",
|
|
23
|
+
"import type { CallToolResult } from '@modelcontextprotocol/server';\nimport { textResult } from './result';\n\n/** What an agent reads when the server failed: nothing about the server leaks. */\nexport const failed = (): CallToolResult =>\n\ttextResult('The server failed to run the operation. Fix: retry later.', true);\n\n/** An unexpected failure goes to `onError` with its cause; the agent gets a generic message, nothing about the server leaks. */\nexport async function guarded(\n\tcontext: { onError: (error: unknown) => void },\n\trun: () => Promise<CallToolResult>,\n): Promise<CallToolResult> {\n\ttry {\n\t\treturn await run();\n\t} catch (error) {\n\t\tcontext.onError(error);\n\t\treturn failed();\n\t}\n}\n",
|
|
24
|
+
"import type {\n\tCallToolResult,\n\tMcpServer,\n\tStandardSchemaWithJSON,\n} from '@modelcontextprotocol/server';\nimport { type ExecuteContext, execute } from '../tools/execute';\nimport { failed, guarded } from '../tools/guard';\nimport { type JsonResult, refused, resultOf } from '../tools/result';\nimport type { JsonSchema, OperationTool } from './types';\n\n/**\n * A JSON Schema as the SDK takes it: advertised as it is, and accepting any\n * value. The arguments are checked by graxia's own variable coercion, whose\n * errors carry a code and a fix.\n */\nexport function advertised(\n\tschema: JsonSchema,\n): StandardSchemaWithJSON<Record<string, unknown>> {\n\treturn {\n\t\t'~standard': {\n\t\t\tversion: 1,\n\t\t\tvendor: 'graxia',\n\t\t\tjsonSchema: { input: () => schema, output: () => schema },\n\t\t\tvalidate: (value) => ({ value: value as Record<string, unknown> }),\n\t\t},\n\t};\n}\n\n/** The fix of a variable graxia refused: an agent has the input schema, not the operation. */\nexport const ARGUMENTS_FIX =\n\t\"Correct the arguments: see the tool's input schema.\";\n\n/** The refusal of arguments the input schema does not have; graphql would drop them silently. */\nfunction unknownArguments(\n\ttool: OperationTool,\n\tvariables: Record<string, unknown>,\n): CallToolResult | undefined {\n\tconst accepted = Object.keys(\n\t\t(tool.inputSchema['properties'] ?? {}) as Record<string, unknown>,\n\t);\n\tconst unknown = Object.keys(variables).filter(\n\t\t(key) => !accepted.includes(key),\n\t);\n\tif (unknown.length === 0) return undefined;\n\treturn refused(\n\t\t`${tool.name} does not take the argument${unknown.length === 1 ? '' : 's'} ${unknown.join(', ')}.`,\n\t\t'MCP_UNKNOWN_ARGUMENT',\n\t\taccepted.length > 0\n\t\t\t? `Send only the arguments the tool accepts: ${accepted.join(', ')}.`\n\t\t\t: 'Send no argument: the tool takes none.',\n\t);\n}\n\n/** A variable error (graphql raises it before any field runs, so it has no path) gets a fix about the arguments. */\nfunction withArgumentsFix(result: CallToolResult): CallToolResult {\n\tconst body = result.structuredContent as JsonResult | undefined;\n\tconst wrong = (error: Record<string, unknown>) =>\n\t\terror['path'] === undefined &&\n\t\t(error['extensions'] as { code?: unknown } | undefined)?.code ===\n\t\t\t'BAD_USER_INPUT';\n\tif (!body?.errors?.some(wrong)) return result;\n\treturn resultOf({\n\t\t...body,\n\t\terrors: body.errors.map((error) =>\n\t\t\twrong(error)\n\t\t\t\t? {\n\t\t\t\t\t\t...error,\n\t\t\t\t\t\textensions: {\n\t\t\t\t\t\t\t...(error['extensions'] as object),\n\t\t\t\t\t\t\tfix: ARGUMENTS_FIX,\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: error,\n\t\t),\n\t});\n}\n\n/** Registers the typed tools one caller may use on its per-request server. */\nexport function registerOperationTools(\n\tserver: McpServer,\n\ttools: readonly OperationTool[],\n\tcontext: ExecuteContext,\n): void {\n\tfor (const tool of tools)\n\t\tserver.registerTool(\n\t\t\ttool.name,\n\t\t\t{\n\t\t\t\ttitle: tool.title,\n\t\t\t\tdescription: tool.description,\n\t\t\t\tinputSchema: advertised(tool.inputSchema),\n\t\t\t\toutputSchema: advertised(tool.outputSchema),\n\t\t\t\tannotations:\n\t\t\t\t\ttool.kind === 'query'\n\t\t\t\t\t\t? { readOnlyHint: true }\n\t\t\t\t\t\t: { readOnlyHint: false, destructiveHint: true },\n\t\t\t},\n\t\t\t(variables = {}) =>\n\t\t\t\tguarded(\n\t\t\t\t\tcontext,\n\t\t\t\t\tasync () =>\n\t\t\t\t\t\tunknownArguments(tool, variables) ??\n\t\t\t\t\t\twithArgumentsFix(\n\t\t\t\t\t\t\tawait execute(context, {\n\t\t\t\t\t\t\t\tdocument: tool.source,\n\t\t\t\t\t\t\t\toperationName: tool.title,\n\t\t\t\t\t\t\t\tvariables,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t),\n\t\t);\n}\n\n/**\n * The caller's view failed to build (`can` threw), so what the caller may\n * use is unknown: a call to a typed tool answers the retry-later error of\n * the other tools, not tool-not-found. For a request that does not list tools.\n */\nexport function registerFailedTools(\n\tserver: McpServer,\n\ttools: readonly OperationTool[],\n): void {\n\tfor (const tool of tools)\n\t\tserver.registerTool(\n\t\t\ttool.name,\n\t\t\t{ inputSchema: advertised({ type: 'object' }) },\n\t\t\tasync () => failed(),\n\t\t);\n}\n",
|
|
25
|
+
"import type { McpServer } from '@modelcontextprotocol/server';\nimport { z } from 'zod';\nimport type { GenericTools } from '../toolset';\nimport { type ExecuteContext, runOperation } from './execute';\nimport { guarded } from './guard';\nimport { overview, SEARCH_LIMIT, searchSdl, typesSdl } from './schema';\nimport { registerStrictRefusals } from './strict';\n\nconst operationInput = z.object({\n\tquery: z.string().describe('The GraphQL document (one operation).'),\n\tvariables: z\n\t\t.record(z.string(), z.unknown())\n\t\t.optional()\n\t\t.describe('The operation variables, as a JSON object.'),\n\toperationName: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe('Which operation to run when the document has several.'),\n});\n\nconst schemaInput = z.object({\n\tsearch: z\n\t\t.string()\n\t\t.optional()\n\t\t.describe('Words to find in type and field names and descriptions.'),\n\ttypes: z\n\t\t.array(z.string())\n\t\t.max(SEARCH_LIMIT)\n\t\t.optional()\n\t\t.describe('Names of the types whose SDL to return.'),\n});\n\n/** What the tools need for one request. */\nexport interface ToolsInput {\n\tcontext: ExecuteContext;\n\tmutations: boolean;\n\t/** How `graphql_query` and `graphql_mutate` stand. */\n\tgeneric: GenericTools;\n\t/** The request lists the tools: what is registered is what is advertised. */\n\tlisting: boolean;\n\t/** The names of the typed tools this caller is offered, for the overview. */\n\ttyped: readonly string[];\n}\n\n/** Registers the generic tools on a per-request server. */\nexport function registerTools(server: McpServer, input: ToolsInput): void {\n\tconst { context, mutations, generic, typed } = input;\n\tconst note = typedNote(typed, generic);\n\tserver.registerTool(\n\t\t'graphql_schema',\n\t\t{\n\t\t\ttitle: 'GraphQL schema',\n\t\t\tdescription:\n\t\t\t\t'Describe the GraphQL API you may use. CALL THIS FIRST. With no input: the available operations and the type names. With { types: [\"Name\"] }: the SDL of those types (descriptions, @needs permissions, @constraint limits and @errors codes included). With { search: \"word\" }: the types whose names or descriptions match. A name not shown here is not available to you.',\n\t\t\tinputSchema: schemaInput,\n\t\t\tannotations: { readOnlyHint: true },\n\t\t},\n\t\t(args) =>\n\t\t\tguarded(context, async () => {\n\t\t\t\tconst view = await context.view();\n\t\t\t\tif (args.types && args.types.length > 0)\n\t\t\t\t\treturn typesSdl(view, args.types, mutations);\n\t\t\t\tif (args.search !== undefined)\n\t\t\t\t\treturn searchSdl(view, args.search, mutations);\n\t\t\t\treturn overview(view, mutations, note);\n\t\t\t}),\n\t);\n\tif (generic === 'refused' && !input.listing)\n\t\tregisterStrictRefusals(server, typed);\n\tif (generic !== 'on') return;\n\tserver.registerTool(\n\t\t'graphql_query',\n\t\t{\n\t\t\ttitle: 'GraphQL query',\n\t\t\tdescription:\n\t\t\t\t'Run a GraphQL query (read only). Call graphql_schema first to learn the fields. Returns { data, errors }; every error has extensions.code and extensions.fix: read the fix. Mutations, subscriptions and introspection (__schema, __type) are refused: use graphql_schema to read the schema. @defer and @stream are not available.',\n\t\t\tinputSchema: operationInput,\n\t\t\tannotations: { readOnlyHint: true },\n\t\t},\n\t\t(args) => guarded(context, () => runOperation('query', args, context)),\n\t);\n\tif (!mutations) return;\n\tserver.registerTool(\n\t\t'graphql_mutate',\n\t\t{\n\t\t\ttitle: 'GraphQL mutation',\n\t\t\tdescription:\n\t\t\t\t'Run a GraphQL mutation (it changes data). Call graphql_schema first to learn the mutations, their @needs permissions and @errors codes. Returns { data, errors }; every error has extensions.code and extensions.fix: read the fix. Queries are refused here: use graphql_query.',\n\t\t\tinputSchema: operationInput,\n\t\t\tannotations: { readOnlyHint: false, destructiveHint: true },\n\t\t},\n\t\t(args) => guarded(context, () => runOperation('mutation', args, context)),\n\t);\n}\n\n/** What the overview says about the typed tools, when the caller has some. */\nfunction typedNote(typed: readonly string[], generic: GenericTools): string {\n\tif (typed.length === 0)\n\t\treturn generic === 'refused'\n\t\t\t? 'No tool runs operations here: this server runs trusted documents only and offers you no typed tool.'\n\t\t\t: '';\n\treturn generic === 'on'\n\t\t? `Typed tools: ${typed.join(', ')}. Prefer the typed tools: each runs one reviewed operation and takes typed arguments; use graphql_query for anything else.`\n\t\t: `Typed tools: ${typed.join(', ')}. They are the only way to run operations here.`;\n}\n",
|
|
26
|
+
"import {\n\ttype GraphQLNamedType,\n\ttype GraphQLObjectType,\n\tisEnumType,\n\tisInputObjectType,\n\tisInterfaceType,\n\tisObjectType,\n} from 'graphql';\nimport { directivesUsedBy, type View } from '../view';\nimport { textResult } from './result';\n\n/** The most types one `search` returns; the answer says when more matched. */\nexport const SEARCH_LIMIT = 50;\n\nconst firstLine = (text: string | null | undefined): string =>\n\ttext ? ` — ${text.trim().split('\\n')[0]}` : '';\n\nfunction rootBlock(\n\tlabel: string,\n\ttype: GraphQLObjectType | undefined,\n): string[] {\n\tif (!type) return [];\n\tconst lines = Object.values(type.getFields())\n\t\t.filter((field) => field.name !== '_empty')\n\t\t.map((field) => {\n\t\t\tconst args = field.args.map((a) => `${a.name}: ${a.type}`).join(', ');\n\t\t\treturn ` ${field.name}${args ? `(${args})` : ''}: ${field.type}${firstLine(field.description)}`;\n\t\t});\n\treturn lines.length > 0 ? [`${label}:`, ...lines, ''] : [];\n}\n\n/** The type names the tools hand out: without `mutations`, the Mutation root is not among them. */\nfunction listed(view: View, mutations: boolean): string[] {\n\tconst root = mutations ? undefined : view.schema.getMutationType()?.name;\n\treturn [...view.types.keys()].filter((name) => name !== root);\n}\n\n/** No input: what the caller can do, and the type names to ask about. */\nexport function overview(view: View, mutations: boolean, note = '') {\n\tconst { schema } = view;\n\tconst lines = [\n\t\t...rootBlock('Query', schema.getQueryType() ?? undefined),\n\t\t...(mutations\n\t\t\t? rootBlock('Mutation', schema.getMutationType() ?? undefined)\n\t\t\t: []),\n\t\t`Types: ${listed(view, mutations).join(', ')}`,\n\t\t'',\n\t\t...(note ? [note, ''] : []),\n\t\t'Next: call graphql_schema with { types: [\"Name\"] } for the SDL of a type, or { search: \"word\" } to find types by name or description.',\n\t];\n\treturn textResult(lines.join('\\n'));\n}\n\nfunction sdlOf(view: View, names: readonly string[]): string {\n\tconst texts = names.map((name) => view.types.get(name) as string);\n\treturn [...directivesUsedBy(view, texts), ...texts].join('\\n\\n');\n}\n\n/** `types`: the SDL of the named types; unknown names are listed with a fix. */\nexport function typesSdl(\n\tview: View,\n\tnames: readonly string[],\n\tmutations: boolean,\n) {\n\tconst offered = new Set(listed(view, mutations));\n\tconst known = names.filter((name) => offered.has(name));\n\tconst unknown = names.filter((name) => !offered.has(name));\n\tconst notes = unknown.map(\n\t\t(name) =>\n\t\t\t`# Unknown type ${name}. Fix: call graphql_schema with no input to list the type names you can use.`,\n\t);\n\tconst body = known.length > 0 ? sdlOf(view, known) : '';\n\treturn textResult(\n\t\t[body, ...notes].filter(Boolean).join('\\n\\n'),\n\t\tknown.length === 0,\n\t);\n}\n\nfunction words(text: string): string[] {\n\treturn text\n\t\t.toLowerCase()\n\t\t.split(/[^\\p{L}\\p{N}_]+/u)\n\t\t.filter(Boolean);\n}\n\nfunction haystack(type: GraphQLNamedType): string {\n\tconst parts: (string | null | undefined)[] = [type.name, type.description];\n\tif (isObjectType(type) || isInterfaceType(type) || isInputObjectType(type))\n\t\tfor (const field of Object.values(type.getFields()))\n\t\t\tparts.push(field.name, field.description);\n\tif (isEnumType(type))\n\t\tfor (const value of type.getValues())\n\t\t\tparts.push(value.name, value.description);\n\treturn parts.filter(Boolean).join(' ').toLowerCase();\n}\n\n/** `search`: the SDL of the types whose name, description, field or value names and descriptions hold every word. */\nexport function searchSdl(view: View, search: string, mutations: boolean) {\n\tconst wanted = words(search);\n\tif (wanted.length === 0)\n\t\treturn textResult(\n\t\t\t'Empty search. Fix: pass a word of a type or field name or description, or call graphql_schema with no input for the overview.',\n\t\t\ttrue,\n\t\t);\n\tconst matches = listed(view, mutations).filter((name) => {\n\t\tconst type = view.schema.getType(name);\n\t\tif (!type) return false;\n\t\tconst text = haystack(type);\n\t\treturn wanted.every((word) => text.includes(word));\n\t});\n\tif (matches.length === 0)\n\t\treturn textResult(\n\t\t\t`No type matches \"${search}\". Fix: try one word, or call graphql_schema with no input for the overview.`,\n\t\t\ttrue,\n\t\t);\n\tconst shown = matches.slice(0, SEARCH_LIMIT);\n\tconst more =\n\t\tmatches.length > shown.length\n\t\t\t? `\\n\\n# ${matches.length - shown.length} more types match. Fix: narrow the search with another word.`\n\t\t\t: '';\n\treturn textResult(sdlOf(view, shown) + more);\n}\n",
|
|
27
|
+
"import { type Can, printSchemaFor } from '@graxia/core/agent';\nimport {\n\tbuildSchema,\n\ttype DefinitionNode,\n\ttype GraphQLSchema,\n\tKind,\n\tparse,\n} from 'graphql';\n\n/** The schema as one caller may see it, with the SDL of each type ready to hand out. */\nexport interface View {\n\t/** The visible schema: validate operations against it. */\n\tschema: GraphQLSchema;\n\t/** SDL of each visible type, by name, in schema order (descriptions and applied agent directives kept). */\n\ttypes: ReadonlyMap<string, string>;\n\t/** SDL of each directive definition the visible SDL declares, by name. */\n\tdirectives: ReadonlyMap<string, string>;\n}\n\nconst nameOf = (definition: DefinitionNode): string | undefined =>\n\t'name' in definition ? definition.name?.value : undefined;\n\n/** Builds the view of a caller (`can` absent: everything). Walks the whole schema, so cache it per kind of caller. */\nexport function buildView(schema: GraphQLSchema, can?: Can): View {\n\tconst sdl = printSchemaFor(schema, can ? { can } : {});\n\tconst types = new Map<string, string>();\n\tconst directives = new Map<string, string>();\n\tfor (const definition of parse(sdl, { noLocation: false }).definitions) {\n\t\tconst name = nameOf(definition);\n\t\tconst loc = definition.loc;\n\t\tif (name === undefined || !loc) continue;\n\t\tconst text = sdl.slice(loc.start, loc.end);\n\t\tif (definition.kind === Kind.DIRECTIVE_DEFINITION)\n\t\t\tdirectives.set(name, text);\n\t\telse if (definition.kind !== Kind.SCHEMA_DEFINITION) types.set(name, text);\n\t}\n\treturn { schema: buildSchema(sdl), types, directives };\n}\n\n/** The directive definitions that the SDL `texts` use, so the output is self-contained. */\nexport function directivesUsedBy(\n\tview: View,\n\ttexts: readonly string[],\n): string[] {\n\tconst joined = texts.join('\\n');\n\treturn [...view.directives]\n\t\t.filter(([name]) => new RegExp(`@${name}\\\\b`).test(joined))\n\t\t.map(([, text]) => text);\n}\n",
|
|
28
|
+
"import type { McpServer } from '@modelcontextprotocol/server';\nimport { advertised } from '../operations/register';\nimport { refused } from './result';\n\n/** The fix of a generic tool called on a strict server: the typed tools the caller has, or that there is none. */\nexport const strictFix = (typed: readonly string[]): string =>\n\ttyped.length > 0\n\t\t? `This server runs trusted documents only: use the typed tools (${typed.join(', ')}).`\n\t\t: 'This server runs trusted documents only and offers you no typed tool: no operation can be run here.';\n\n/**\n * graxia runs trusted documents in strict mode: a document an agent writes\n * must not run, though `graxia.execute` (in process) would run it. So\n * `graphql_query` and `graphql_mutate` only answer core's\n * `PERSISTED_QUERY_ONLY` refusal. Register them for a request that calls\n * tools and does not list them: they are never advertised.\n */\nexport function registerStrictRefusals(\n\tserver: McpServer,\n\ttyped: readonly string[],\n): void {\n\tfor (const name of ['graphql_query', 'graphql_mutate'])\n\t\tserver.registerTool(\n\t\t\tname,\n\t\t\t{ inputSchema: advertised({ type: 'object' }) },\n\t\t\tasync () =>\n\t\t\t\trefused(\n\t\t\t\t\t'Only persisted documents are allowed.',\n\t\t\t\t\t'PERSISTED_QUERY_ONLY',\n\t\t\t\t\tstrictFix(typed),\n\t\t\t\t),\n\t\t);\n}\n",
|
|
29
|
+
"import { GraxiaConfigError } from '@graxia/core';\nimport { buildOperationTools } from './operations/build';\nimport { operationsError, problem } from './operations/problems';\nimport type { OperationTool } from './operations/types';\nimport { createVisibleTools } from './operations/visible';\nimport type { McpHost, McpOptions } from './options';\nimport type { View } from './view';\n\n/**\n * How `graphql_query` and `graphql_mutate` stand: `on`, `off`\n * (`genericTools: false`), or `refused` when graxia runs trusted documents\n * in strict mode, where a document an agent writes must not run.\n */\nexport type GenericTools = 'on' | 'off' | 'refused';\n\n/** The tools of one `createMcp`, decided once at boot. */\nexport interface Toolset {\n\t/** The typed tools of `operations`; empty without it. */\n\ttyped: readonly OperationTool[];\n\tgeneric: GenericTools;\n\t/** The typed tools a view allows. */\n\tvisible(view: View): readonly OperationTool[];\n\t/**\n\t * Whether `name` is a tool that writes and that this caller would be\n\t * offered with the write scope: `graphql_mutate`, or the typed tool of a\n\t * mutation the caller's view allows. A view that fails to build offers none.\n\t */\n\twrites(name: string, view: () => Promise<View>): Promise<boolean>;\n}\n\n/** The typed tools of `operations`, built once; `genericTools: false` needs at least one. */\nfunction typedTools(\n\tgraxia: McpHost<any>,\n\toptions: McpOptions<any>,\n\tmutations: boolean,\n): OperationTool[] {\n\tconst generic = options.genericTools ?? true;\n\tif (!options.operations) {\n\t\tif (!generic)\n\t\t\tthrow new GraxiaConfigError(\n\t\t\t\t'createMcp: genericTools is false and there is no operations: an agent would have nothing to call. Fix: pass operations: { documents: manifest }, or remove genericTools: false.',\n\t\t\t);\n\t\treturn [];\n\t}\n\tconst typed = buildOperationTools(\n\t\tgraxia.schema,\n\t\toptions.operations,\n\t\tmutations,\n\t);\n\tif (!generic && typed.length === 0) throw operationsError([problem.empty()]);\n\treturn typed;\n}\n\n/**\n * Builds the tools of a server: the typed tools of `operations`, and how the\n * generic ones stand.\n * @throws {GraxiaConfigError} for a problem in `operations`, or `genericTools: false` with no typed tool.\n */\nexport function createToolset(\n\tgraxia: McpHost<any>,\n\toptions: McpOptions<any>,\n\tmutations: boolean,\n\tonError: (error: unknown) => void,\n): Toolset {\n\tconst typed = typedTools(graxia, options, mutations);\n\tconst generic: GenericTools =\n\t\toptions.genericTools === false\n\t\t\t? 'off'\n\t\t\t: graxia.trustedDocuments?.mode === 'strict'\n\t\t\t\t? 'refused'\n\t\t\t\t: 'on';\n\tif (generic === 'refused' && typed.length === 0)\n\t\tonError(\n\t\t\tnew GraxiaConfigError(\n\t\t\t\t'createMcp: graxia runs trusted documents in strict mode and `operations` gives no tool: agents can read the schema but run nothing. Fix: pass `operations: { documents }`.',\n\t\t\t),\n\t\t);\n\tconst visible = createVisibleTools(typed);\n\tconst writing = new Map(\n\t\ttyped.filter((tool) => tool.kind === 'mutation').map((t) => [t.name, t]),\n\t);\n\treturn {\n\t\ttyped,\n\t\tgeneric,\n\t\tvisible,\n\t\tasync writes(name, view) {\n\t\t\tif (name === 'graphql_mutate') return generic === 'on';\n\t\t\tconst tool = writing.get(name);\n\t\t\tif (!tool) return false;\n\t\t\ttry {\n\t\t\t\treturn visible(await view()).includes(tool);\n\t\t\t} catch {\n\t\t\t\t// The factory reports the failure; an unknown view opens nothing.\n\t\t\t\treturn false;\n\t\t\t}\n\t\t},\n\t};\n}\n",
|
|
30
|
+
"import {\n\ttype DocumentNode,\n\ttype GraphQLSchema,\n\tKind,\n\tNoSchemaIntrospectionCustomRule,\n\ttype OperationDefinitionNode,\n\tparse,\n\tspecifiedRules,\n\tvalidate,\n} from 'graphql';\nimport { incrementalDirective } from '../tools/operation';\nimport { type ManifestEntry, manifestEntries } from './documents';\nimport { inputSchemaOf } from './input-schema';\nimport { RESERVED_PREFIX, toolNameOf } from './naming';\nimport { outputSchemaOf } from './output-schema';\nimport { MAX_TOOL_NAME, operationsError, problem } from './problems';\nimport type { McpOperationsOptions, OperationTool } from './types';\n\n/** A named operation that becomes a tool. */\ninterface Wanted {\n\tname: string;\n\tnode: OperationDefinitionNode;\n}\n\ninterface Build {\n\tschema: GraphQLSchema;\n\toptions: McpOperationsOptions;\n\tmutations: boolean;\n\tproblems: string[];\n\ttools: Map<string, OperationTool>;\n\t/** Every operation name the documents hold, kept or not. */\n\tnames: Set<string>;\n}\n\n/** A manifest entry whose source is a string that parses. */\ninterface Parsed {\n\tid: string;\n\tsource: string;\n\tdocument: DocumentNode;\n}\n\nfunction parsed(entry: ManifestEntry, build: Build): Parsed | undefined {\n\tconst { id, source } = entry;\n\tif (typeof source !== 'string' || source.trim() === '') {\n\t\tbuild.problems.push(problem.source(id));\n\t\treturn undefined;\n\t}\n\ttry {\n\t\treturn { id, source, document: parse(source) };\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tbuild.problems.push(problem.parse(entry.id, message));\n\t\treturn undefined;\n\t}\n}\n\n/** The operations of a document that become tools: named queries, mutations when on, kept by `include`. */\nfunction wanted(document: DocumentNode, id: string, build: Build): Wanted[] {\n\tconst kept: Wanted[] = [];\n\tfor (const definition of document.definitions) {\n\t\tif (definition.kind !== Kind.OPERATION_DEFINITION) continue;\n\t\tif (definition.name) build.names.add(definition.name.value);\n\t\tconst kind = definition.operation;\n\t\tif (kind === 'subscription') continue;\n\t\tif (kind === 'mutation' && !build.mutations) continue;\n\t\tif (!definition.name) {\n\t\t\tbuild.problems.push(problem.anonymous(id));\n\t\t\tcontinue;\n\t\t}\n\t\tconst name = definition.name.value;\n\t\tif (build.options.include && !build.options.include({ name, kind, id }))\n\t\t\tcontinue;\n\t\tkept.push({ name, node: definition });\n\t}\n\treturn kept;\n}\n\n/** The description of an operation: the one of `descriptions`, else its own. */\nfunction descriptionOf(wanted: Wanted, build: Build): string {\n\tconst given = build.options.descriptions;\n\tconst own =\n\t\tgiven && Object.hasOwn(given, wanted.name) ? given[wanted.name] : undefined;\n\treturn String(own ?? wanted.node.description?.value ?? '').trim();\n}\n\nfunction addTool(wanted: Wanted, entry: Parsed, build: Build): void {\n\tconst { name: title, node: operation } = wanted;\n\tconst { id, document } = entry;\n\tconst name = toolNameOf(title);\n\tconst description = descriptionOf(wanted, build);\n\tconst before = build.problems.length;\n\tif (description === '') build.problems.push(problem.description(title, id));\n\tif (name.startsWith(RESERVED_PREFIX))\n\t\tbuild.problems.push(problem.reserved(title, id, name));\n\tif (name.length > MAX_TOOL_NAME)\n\t\tbuild.problems.push(problem.tooLong(title, id, name));\n\tconst taken = build.tools.get(name);\n\tif (taken)\n\t\tbuild.problems.push(\n\t\t\tproblem.duplicate(\n\t\t\t\tname,\n\t\t\t\t{ name: taken.title, id: taken.id },\n\t\t\t\t{ name: title, id },\n\t\t\t),\n\t\t);\n\tif (build.problems.length > before) return;\n\tbuild.tools.set(name, {\n\t\tname,\n\t\ttitle,\n\t\tdescription,\n\t\tkind: operation.operation === 'mutation' ? 'mutation' : 'query',\n\t\tid,\n\t\tsource: entry.source,\n\t\tdocument,\n\t\tinputSchema: inputSchemaOf(build.schema, document, operation),\n\t\toutputSchema: outputSchemaOf(build.schema, document, operation),\n\t});\n}\n\nfunction addDocument(raw: ManifestEntry, build: Build): void {\n\tconst entry = parsed(raw, build);\n\tif (!entry) return;\n\tconst { document } = entry;\n\tconst operations = wanted(document, entry.id, build);\n\tif (operations.length === 0) return;\n\tconst names = operations.map((o) => o.name);\n\tconst directive = incrementalDirective(document);\n\tif (directive) {\n\t\tbuild.problems.push(\n\t\t\tproblem.incremental(names.join(', '), entry.id, directive),\n\t\t);\n\t\treturn;\n\t}\n\tconst errors = validate(build.schema, document, specifiedRules);\n\tif (errors.length > 0) {\n\t\tbuild.problems.push(\n\t\t\tproblem.invalid(\n\t\t\t\tnames,\n\t\t\t\tentry.id,\n\t\t\t\terrors.map((e) => e.message),\n\t\t\t),\n\t\t);\n\t\treturn;\n\t}\n\tif (\n\t\tvalidate(build.schema, document, [NoSchemaIntrospectionCustomRule]).length >\n\t\t0\n\t) {\n\t\tbuild.problems.push(problem.introspection(names, entry.id));\n\t\treturn;\n\t}\n\tfor (const operation of operations) addTool(operation, entry, build);\n}\n\n/** A `descriptions` key that names no operation of the documents: a typo would silently do nothing. */\nfunction checkDescriptions(build: Build): void {\n\tfor (const key of Object.keys(build.options.descriptions ?? {})) {\n\t\tif (build.names.has(key)) continue;\n\t\tconst close = [...build.names].find(\n\t\t\t(name) => name.toLowerCase() === key.toLowerCase(),\n\t\t);\n\t\tbuild.problems.push(problem.unusedDescription(key, close));\n\t}\n}\n\n/**\n * Builds the typed tools of `operations`, once: one per named query of each\n * document (and per mutation when `mutations` is on), with its input and\n * output schemas.\n * @throws {GraxiaConfigError} listing every problem, each with its fix.\n */\nexport function buildOperationTools(\n\tschema: GraphQLSchema,\n\toptions: McpOperationsOptions,\n\tmutations: boolean,\n): OperationTool[] {\n\tconst build: Build = {\n\t\tschema,\n\t\toptions,\n\t\tmutations,\n\t\tproblems: [],\n\t\ttools: new Map(),\n\t\tnames: new Set(),\n\t};\n\tconst entries = manifestEntries(options?.documents);\n\tif (!entries) throw operationsError([problem.manifest()]);\n\tfor (const entry of entries) addDocument(entry, build);\n\tcheckDescriptions(build);\n\tif (build.problems.length > 0) throw operationsError(build.problems);\n\treturn [...build.tools.values()];\n}\n",
|
|
31
|
+
"import type { TrustedManifest } from '@graxia/core';\n\n/** One document of a manifest. */\nexport interface ManifestEntry {\n\tid: string;\n\tsource: unknown;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * The documents of a manifest in any of core's three formats (a `Map`, an\n * Apollo persisted query manifest, an object of id to source), in order.\n * `undefined` when it is none of them. Sources are not checked here.\n */\nexport function manifestEntries(\n\tmanifest: TrustedManifest | unknown,\n): ManifestEntry[] | undefined {\n\tif (manifest instanceof Map)\n\t\treturn [...manifest].map(([id, source]) => ({ id: String(id), source }));\n\tif (!isRecord(manifest)) return undefined;\n\tif (manifest['format'] === 'apollo-persisted-query-manifest') {\n\t\tconst { operations } = manifest;\n\t\tif (!Array.isArray(operations)) return undefined;\n\t\treturn operations.map((operation, index) => ({\n\t\t\tid: isRecord(operation) ? String(operation['id']) : `#${index}`,\n\t\t\tsource: isRecord(operation) ? operation['body'] : undefined,\n\t\t}));\n\t}\n\treturn Object.entries(manifest).map(([id, source]) => ({ id, source }));\n}\n",
|
|
32
|
+
"import {\n\ttype DocumentNode,\n\ttype GraphQLInputType,\n\ttype GraphQLSchema,\n\tisNonNullType,\n\ttype OperationDefinitionNode,\n\ttypeFromAST,\n\tvalueFromASTUntyped,\n} from 'graphql';\nimport { constrained, tightest } from './constraint';\nimport { newDefs, typeSchema } from './input-type';\nimport type { JsonSchema } from './types';\nimport { variableUsages } from './variable-usage';\n\n/**\n * The JSON Schema (2020-12) of a tool's input: one property per variable of\n * `operation`. A non-null variable without a default is required; a default\n * goes to `default`; the description is the variable's own, else the one of\n * the argument or input field it feeds; `@constraint` comes from input fields\n * and, for a variable, from the arguments it is used at (the tightest when\n * they differ). The document must be valid against `schema`.\n */\nexport function inputSchemaOf(\n\tschema: GraphQLSchema,\n\tdocument: DocumentNode,\n\toperation: OperationDefinitionNode,\n): JsonSchema {\n\tconst defs = newDefs();\n\tconst usages = variableUsages(schema, document, operation);\n\tconst properties: Record<string, JsonSchema> = {};\n\tconst required: string[] = [];\n\tfor (const definition of operation.variableDefinitions ?? []) {\n\t\tconst name = definition.variable.name.value;\n\t\tconst type = typeFromAST(schema, definition.type) as\n\t\t\t| GraphQLInputType\n\t\t\t| undefined;\n\t\tif (!type) continue;\n\t\tconst usage = usages.get(name);\n\t\tconst description = definition.description?.value ?? usage?.description;\n\t\tproperties[name] = {\n\t\t\t...constrained(\n\t\t\t\ttypeSchema(type, defs),\n\t\t\t\ttightest(usage?.constraints ?? []),\n\t\t\t),\n\t\t\t...(description ? { description } : {}),\n\t\t\t...(definition.defaultValue\n\t\t\t\t? { default: valueFromASTUntyped(definition.defaultValue) }\n\t\t\t\t: {}),\n\t\t};\n\t\tif (isNonNullType(type) && !definition.defaultValue) required.push(name);\n\t}\n\treturn {\n\t\ttype: 'object',\n\t\tproperties,\n\t\t...(required.length > 0 ? { required } : {}),\n\t\tadditionalProperties: false,\n\t\t...(Object.keys(defs).length > 0 ? { $defs: defs } : {}),\n\t};\n}\n",
|
|
33
|
+
"import type { Constraint } from '@graxia/core/agent';\nimport type { JsonSchema } from './types';\n\n/** `@constraint` argument to JSON Schema keyword, for a string or a number. */\nconst LEAF: Readonly<Partial<Record<keyof Constraint, string>>> = {\n\tminLength: 'minLength',\n\tmaxLength: 'maxLength',\n\tmin: 'minimum',\n\tmax: 'maximum',\n\texclusiveMin: 'exclusiveMinimum',\n\texclusiveMax: 'exclusiveMaximum',\n\tmultipleOf: 'multipleOf',\n\tpattern: 'pattern',\n\tformat: 'format',\n};\n/** `@constraint` argument to JSON Schema keyword, for a list. */\nconst LIST: Readonly<Partial<Record<keyof Constraint, string>>> = {\n\tminItems: 'minItems',\n\tmaxItems: 'maxItems',\n};\n\nconst LOWER = ['minLength', 'min', 'exclusiveMin', 'minItems'] as const;\nconst UPPER = ['maxLength', 'max', 'exclusiveMax', 'maxItems'] as const;\nconst EXACT = ['multipleOf', 'pattern', 'format'] as const;\n\nconst isArray = (node: JsonSchema): boolean =>\n\tnode['type'] === 'array' ||\n\t(Array.isArray(node['type']) && node['type'].includes('array'));\n\nfunction keywords(\n\tconstraint: Constraint,\n\tmap: Readonly<Partial<Record<keyof Constraint, string>>>,\n): JsonSchema {\n\tconst out: JsonSchema = {};\n\tfor (const [key, keyword] of Object.entries(map)) {\n\t\tconst value = constraint[key as keyof Constraint];\n\t\tif (value !== undefined && value !== null) out[keyword] = value;\n\t}\n\treturn out;\n}\n\n/**\n * The schema `node` with the limits of `constraint`. On a list, `minItems`\n * and `maxItems` go on the outermost array and the other limits on its\n * innermost items; on a reference or a union nothing is added.\n */\nexport function constrained(\n\tnode: JsonSchema,\n\tconstraint: Constraint | undefined,\n): JsonSchema {\n\tif (!constraint) return node;\n\tif (isArray(node))\n\t\treturn {\n\t\t\t...node,\n\t\t\t...keywords(constraint, LIST),\n\t\t\titems: leafConstrained(node['items'] as JsonSchema, constraint),\n\t\t};\n\treturn leafConstrained(node, constraint);\n}\n\nfunction leafConstrained(node: JsonSchema, constraint: Constraint): JsonSchema {\n\tif (isArray(node))\n\t\treturn {\n\t\t\t...node,\n\t\t\titems: leafConstrained(node['items'] as JsonSchema, constraint),\n\t\t};\n\tif ('$ref' in node || 'anyOf' in node) return node;\n\treturn { ...node, ...keywords(constraint, LEAF) };\n}\n\n/**\n * One constraint a value must meet to satisfy all of `constraints` (a\n * variable used at several arguments): the tightest bound of each kind;\n * `pattern`, `format` and `multipleOf` are kept when the usages that declare\n * one agree, and dropped when they differ (graxia's own checks still apply).\n */\nexport function tightest(\n\tconstraints: readonly Constraint[],\n): Constraint | undefined {\n\tif (constraints.length === 0) return undefined;\n\tconst out: Record<string, unknown> = {};\n\tconst values = <K extends keyof Constraint>(key: K) =>\n\t\tconstraints\n\t\t\t.map((c) => c[key])\n\t\t\t.filter((v): v is NonNullable<Constraint[K]> => v != null);\n\tfor (const key of LOWER)\n\t\tif (values(key).length > 0) out[key] = Math.max(...values(key));\n\tfor (const key of UPPER)\n\t\tif (values(key).length > 0) out[key] = Math.min(...values(key));\n\tfor (const key of EXACT) {\n\t\tconst distinct = new Set<unknown>(values(key));\n\t\tif (distinct.size === 1) out[key] = [...distinct][0];\n\t}\n\treturn Object.keys(out).length > 0 ? (out as Constraint) : undefined;\n}\n",
|
|
34
|
+
"import { constraintOf } from '@graxia/core/agent';\nimport {\n\ttype GraphQLEnumType,\n\ttype GraphQLInputField,\n\ttype GraphQLInputObjectType,\n\ttype GraphQLInputType,\n\tisEnumType,\n\tisInputObjectType,\n\tisListType,\n\tisNonNullType,\n\tisRequiredInputField,\n\tvalueFromASTUntyped,\n} from 'graphql';\nimport { constrained } from './constraint';\nimport type { JsonSchema } from './types';\n\n/** The `$defs` of one input schema: every input object the variables reach, by type name. Make it with {@link newDefs}. */\nexport type Defs = Record<string, JsonSchema>;\n\n/** An empty {@link Defs}, without a prototype: a type may be named `constructor` or `toString`. */\nexport const newDefs = (): Defs => Object.create(null) as Defs;\n\n/** The JSON type of each built-in scalar. */\nexport const SCALARS: Readonly<Record<string, string>> = {\n\tInt: 'integer',\n\tFloat: 'number',\n\tString: 'string',\n\tID: 'string',\n\tBoolean: 'boolean',\n};\n\nconst described = (description: string | null | undefined): JsonSchema =>\n\tdescription ? { description } : {};\n\n/** An enum as its value names; the description lists the values that have one. */\nexport function enumSchema(type: GraphQLEnumType): JsonSchema {\n\tconst values = type.getValues();\n\tconst lines = values\n\t\t.filter((value) => value.description)\n\t\t.map((value) => `- ${value.name}: ${value.description}`);\n\tconst description = [type.description, ...lines].filter(Boolean).join('\\n');\n\treturn {\n\t\ttype: 'string',\n\t\tenum: values.map((value) => value.name),\n\t\t...described(description),\n\t};\n}\n\n/** The same schema, accepting `null` too. */\nexport function nullable(node: JsonSchema): JsonSchema {\n\tif ('$ref' in node) return { anyOf: [node, { type: 'null' }] };\n\tif (typeof node['type'] !== 'string') return node;\n\treturn {\n\t\t...node,\n\t\ttype: [node['type'], 'null'],\n\t\t...(Array.isArray(node['enum']) ? { enum: [...node['enum'], null] } : {}),\n\t};\n}\n\n/** The default of an input field, when it declares one. */\nfunction defaultOf(field: GraphQLInputField): { default?: unknown } {\n\tconst declared = field.default;\n\tif (declared?.literal)\n\t\treturn { default: valueFromASTUntyped(declared.literal) };\n\tif (declared && 'value' in declared) return { default: declared.value };\n\t// Code-first schemas (and graphql 16's) set `defaultValue`.\n\tif (field.defaultValue !== undefined) return { default: field.defaultValue };\n\treturn {};\n}\n\nfunction fieldSchema(field: GraphQLInputField, defs: Defs): JsonSchema {\n\treturn {\n\t\t...constrained(typeSchema(field.type, defs), constraintOf(field)),\n\t\t...described(field.description),\n\t\t...defaultOf(field),\n\t\t...(field.deprecationReason ? { deprecated: true } : {}),\n\t};\n}\n\nfunction objectSchema(type: GraphQLInputObjectType, defs: Defs): JsonSchema {\n\tconst fields = Object.values(type.getFields());\n\tif (type.isOneOf)\n\t\treturn {\n\t\t\ttype: 'object',\n\t\t\t...described(type.description),\n\t\t\toneOf: fields.map((field) => ({\n\t\t\t\tproperties: {\n\t\t\t\t\t[field.name]: {\n\t\t\t\t\t\t...constrained(valueSchema(field.type, defs), constraintOf(field)),\n\t\t\t\t\t\t...described(field.description),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\trequired: [field.name],\n\t\t\t\tadditionalProperties: false,\n\t\t\t})),\n\t\t};\n\tconst required = fields.filter(isRequiredInputField).map((f) => f.name);\n\treturn {\n\t\ttype: 'object',\n\t\t...described(type.description),\n\t\tproperties: Object.fromEntries(\n\t\t\tfields.map((field) => [field.name, fieldSchema(field, defs)]),\n\t\t),\n\t\t...(required.length > 0 ? { required } : {}),\n\t\tadditionalProperties: false,\n\t};\n}\n\n/** The schema of a value of `type` that is not `null`. */\nfunction valueSchema(type: GraphQLInputType, defs: Defs): JsonSchema {\n\tif (isNonNullType(type)) return valueSchema(type.ofType, defs);\n\tif (isListType(type))\n\t\treturn { type: 'array', items: typeSchema(type.ofType, defs) };\n\tif (isEnumType(type)) return enumSchema(type);\n\tif (isInputObjectType(type)) {\n\t\tif (!Object.hasOwn(defs, type.name)) {\n\t\t\t// Reserved before it is filled, so a recursive input type ends on its own $ref.\n\t\t\tdefs[type.name] = {};\n\t\t\tdefs[type.name] = objectSchema(type, defs);\n\t\t}\n\t\treturn { $ref: `#/$defs/${type.name}` };\n\t}\n\tconst builtIn = SCALARS[type.name];\n\t// A custom scalar accepts any JSON value: its serialized form is not known here.\n\treturn builtIn ? { type: builtIn } : described(type.description);\n}\n\n/**\n * The JSON Schema of a GraphQL input type. Input objects go to `defs` and are\n * referenced, so recursive types work; a nullable type also accepts `null`.\n */\nexport function typeSchema(type: GraphQLInputType, defs: Defs): JsonSchema {\n\treturn isNonNullType(type)\n\t\t? valueSchema(type.ofType, defs)\n\t\t: nullable(valueSchema(type, defs));\n}\n",
|
|
35
|
+
"import { type Constraint, constraintOf } from '@graxia/core/agent';\nimport {\n\ttype DocumentNode,\n\ttype FragmentDefinitionNode,\n\ttype GraphQLArgument,\n\ttype GraphQLInputField,\n\ttype GraphQLSchema,\n\tgetNamedType,\n\tisInputObjectType,\n\tKind,\n\ttype OperationDefinitionNode,\n\tTypeInfo,\n\tvisit,\n\tvisitWithTypeInfo,\n} from 'graphql';\n\n/** What the places a variable is used at say about it. */\nexport interface VariableUsage {\n\t/** The `@constraint` of each argument or input field the variable feeds. */\n\tconstraints: Constraint[];\n\t/** The description of the first such argument or input field that has one. */\n\tdescription?: string;\n}\n\n/** The operation and the fragments it reaches, through spreads of spreads. */\nfunction reachable(\n\tdocument: DocumentNode,\n\toperation: OperationDefinitionNode,\n): DocumentNode {\n\tconst fragments = new Map<string, FragmentDefinitionNode>();\n\tfor (const definition of document.definitions)\n\t\tif (definition.kind === Kind.FRAGMENT_DEFINITION)\n\t\t\tfragments.set(definition.name.value, definition);\n\tconst reached = new Set<FragmentDefinitionNode>();\n\tconst follow = (node: OperationDefinitionNode | FragmentDefinitionNode) =>\n\t\tvisit(node, {\n\t\t\tFragmentSpread(spread) {\n\t\t\t\tconst fragment = fragments.get(spread.name.value);\n\t\t\t\tif (!fragment || reached.has(fragment)) return;\n\t\t\t\treached.add(fragment);\n\t\t\t\tfollow(fragment);\n\t\t\t},\n\t\t});\n\tfollow(operation);\n\treturn { kind: Kind.DOCUMENT, definitions: [operation, ...reached] };\n}\n\n/**\n * Where each variable of `operation` is used as a whole argument or input\n * field value (in the operation and the fragments it reaches): the\n * constraints and the description of those arguments and fields.\n */\nexport function variableUsages(\n\tschema: GraphQLSchema,\n\tdocument: DocumentNode,\n\toperation: OperationDefinitionNode,\n): Map<string, VariableUsage> {\n\tconst usages = new Map<string, VariableUsage>();\n\tconst note = (name: string, target: GraphQLArgument | GraphQLInputField) => {\n\t\tconst usage = usages.get(name) ?? { constraints: [] };\n\t\tconst constraint = constraintOf(target);\n\t\tif (constraint) usage.constraints.push(constraint);\n\t\tif (usage.description === undefined && target.description)\n\t\t\tusage.description = target.description;\n\t\tusages.set(name, usage);\n\t};\n\tconst typeInfo = new TypeInfo(schema);\n\tvisit(\n\t\treachable(document, operation),\n\t\tvisitWithTypeInfo(typeInfo, {\n\t\t\tVariable(node, _key, parent) {\n\t\t\t\tif (!parent || Array.isArray(parent)) return;\n\t\t\t\tconst holder = parent as { kind: string; name?: { value: string } };\n\t\t\t\tif (holder.kind === Kind.ARGUMENT) {\n\t\t\t\t\tconst argument = typeInfo.getArgument();\n\t\t\t\t\tif (argument) note(node.name.value, argument);\n\t\t\t\t} else if (holder.kind === Kind.OBJECT_FIELD) {\n\t\t\t\t\tconst object = typeInfo.getParentInputType();\n\t\t\t\t\tconst named = object ? getNamedType(object) : undefined;\n\t\t\t\t\tconst field = isInputObjectType(named)\n\t\t\t\t\t\t? named.getFields()[holder.name?.value ?? '']\n\t\t\t\t\t\t: undefined;\n\t\t\t\t\tif (field) note(node.name.value, field);\n\t\t\t\t}\n\t\t\t},\n\t\t}),\n\t);\n\treturn usages;\n}\n",
|
|
36
|
+
"/** The tool name of an operation: its name in snake_case (`BookById` is `book_by_id`, `getHTTPStatus` is `get_http_status`). */\nexport function toolNameOf(operationName: string): string {\n\treturn operationName\n\t\t.replace(/([a-z0-9])([A-Z])/g, '$1_$2')\n\t\t.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')\n\t\t.toLowerCase();\n}\n\n/** Tool names starting with this are the generic tools' (`graphql_schema`, `graphql_query`, `graphql_mutate`). */\nexport const RESERVED_PREFIX = 'graphql_';\n",
|
|
37
|
+
"import {\n\ttype DocumentNode,\n\ttype FieldNode,\n\ttype FragmentDefinitionNode,\n\ttype GraphQLCompositeType,\n\ttype GraphQLOutputType,\n\ttype GraphQLSchema,\n\tisAbstractType,\n\tisCompositeType,\n\tisEnumType,\n\tisListType,\n\tisNonNullType,\n\tisObjectType,\n\tisUnionType,\n\tKind,\n\ttype OperationDefinitionNode,\n\ttype SelectionSetNode,\n} from 'graphql';\nimport { enumSchema, nullable, SCALARS } from './input-type';\nimport type { JsonSchema } from './types';\n\n/** The `errors` of a result: GraphQL errors, each with graxia's `extensions.code` and `extensions.fix`. */\nconst ERRORS: JsonSchema = {\n\ttype: 'array',\n\titems: {\n\t\ttype: 'object',\n\t\tproperties: {\n\t\t\tmessage: { type: 'string' },\n\t\t\tpath: { type: 'array', items: { type: ['string', 'integer'] } },\n\t\t\textensions: {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: { code: { type: 'string' }, fix: { type: 'string' } },\n\t\t\t},\n\t\t},\n\t\trequired: ['message'],\n\t},\n};\n\ninterface Walk {\n\tschema: GraphQLSchema;\n\tfragments: ReadonlyMap<string, FragmentDefinitionNode>;\n}\n\n/** A selection set on an object, and whether it applies to every such object (`sure`). */\ninterface Origin {\n\tset: SelectionSetNode;\n\tsure: boolean;\n}\n\n/** A field node under a response key; `sure` when it is selected on every object that has the key's parent. */\ninterface Selected {\n\tnode: FieldNode;\n\tsure: boolean;\n}\n\n/** One response key: the fields selected under it, grouped by their type, and the origins that always select it. */\ninterface Slot {\n\tsureIn: Set<Origin>;\n\ttypename: boolean;\n\tbyType: Map<string, { type: GraphQLOutputType; nodes: Selected[] }>;\n}\n\nconst conditional = (node: {\n\tdirectives?: readonly { name: { value: string } }[] | undefined;\n}) =>\n\t(node.directives ?? []).some(\n\t\t(d) => d.name.value === 'skip' || d.name.value === 'include',\n\t);\n\n/** Whether a fragment on `condition` applies to every object a field of type `parent` returns. */\nfunction covers(\n\tschema: GraphQLSchema,\n\tparent: GraphQLCompositeType,\n\tcondition: GraphQLCompositeType,\n): boolean {\n\tif (condition === parent || isObjectType(parent)) return true;\n\treturn schema\n\t\t.getPossibleTypes(parent)\n\t\t.every((t) =>\n\t\t\tisAbstractType(condition)\n\t\t\t\t? schema.isSubType(condition, t)\n\t\t\t\t: t === condition,\n\t\t);\n}\n\nfunction collect(\n\twalk: Walk,\n\tparent: GraphQLCompositeType,\n\tset: SelectionSetNode,\n\talways: boolean,\n\torigin: Origin,\n\tslots: Map<string, Slot>,\n): void {\n\tfor (const selection of set.selections) {\n\t\tconst sure = always && !conditional(selection);\n\t\tif (selection.kind === Kind.FIELD) {\n\t\t\tconst key = selection.alias?.value ?? selection.name.value;\n\t\t\tconst slot = slots.get(key) ?? {\n\t\t\t\tsureIn: new Set(),\n\t\t\t\ttypename: false,\n\t\t\t\tbyType: new Map(),\n\t\t\t};\n\t\t\tslots.set(key, slot);\n\t\t\tif (sure) slot.sureIn.add(origin);\n\t\t\tconst field = isUnionType(parent)\n\t\t\t\t? undefined\n\t\t\t\t: parent.getFields()[selection.name.value];\n\t\t\tif (!field) {\n\t\t\t\tslot.typename = true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst group = slot.byType.get(String(field.type)) ?? {\n\t\t\t\ttype: field.type,\n\t\t\t\tnodes: [],\n\t\t\t};\n\t\t\tgroup.nodes.push({ node: selection, sure: sure && origin.sure });\n\t\t\tslot.byType.set(String(field.type), group);\n\t\t\tcontinue;\n\t\t}\n\t\tconst fragment =\n\t\t\tselection.kind === Kind.FRAGMENT_SPREAD\n\t\t\t\t? walk.fragments.get(selection.name.value)\n\t\t\t\t: selection;\n\t\tif (!fragment) continue;\n\t\tconst named = fragment.typeCondition\n\t\t\t? walk.schema.getType(fragment.typeCondition.name.value)\n\t\t\t: parent;\n\t\tif (!isCompositeType(named)) continue;\n\t\tcollect(\n\t\t\twalk,\n\t\t\tnamed,\n\t\t\tfragment.selectionSet,\n\t\t\tsure && covers(walk.schema, parent, named),\n\t\t\torigin,\n\t\t\tslots,\n\t\t);\n\t}\n}\n\n/**\n * The object the selection sets `origins` produce on `parent`, fragments\n * merged. A key is required when an origin that applies to every object\n * always selects it, or when every origin does: several field nodes can\n * share one response key, and an object may come from only some of them.\n */\nfunction objectOf(\n\twalk: Walk,\n\tparent: GraphQLCompositeType,\n\torigins: readonly Origin[],\n): JsonSchema {\n\tconst slots = new Map<string, Slot>();\n\tfor (const origin of origins)\n\t\tcollect(walk, parent, origin.set, true, origin, slots);\n\tconst properties: Record<string, JsonSchema> = {};\n\tfor (const [key, slot] of slots) {\n\t\tconst shapes = [...slot.byType.values()].map((group) =>\n\t\t\ttypeOf(walk, group.type, group.nodes),\n\t\t);\n\t\tif (slot.typename) shapes.unshift({ type: 'string' });\n\t\tproperties[key] =\n\t\t\tshapes.length === 1 ? (shapes[0] as JsonSchema) : { anyOf: shapes };\n\t}\n\tconst required = [...slots]\n\t\t.filter(\n\t\t\t([, slot]) =>\n\t\t\t\tslot.sureIn.size === origins.length ||\n\t\t\t\t[...slot.sureIn].some((origin) => origin.sure),\n\t\t)\n\t\t.map(([key]) => key);\n\treturn {\n\t\ttype: 'object',\n\t\tproperties,\n\t\t...(required.length > 0 ? { required } : {}),\n\t};\n}\n\nfunction shapeOf(\n\twalk: Walk,\n\ttype: GraphQLOutputType,\n\tnodes: readonly Selected[],\n): JsonSchema {\n\tif (isNonNullType(type)) return shapeOf(walk, type.ofType, nodes);\n\tif (isListType(type))\n\t\treturn { type: 'array', items: typeOf(walk, type.ofType, nodes) };\n\tif (isCompositeType(type))\n\t\treturn objectOf(\n\t\t\twalk,\n\t\t\ttype,\n\t\t\tnodes.flatMap(({ node, sure }) =>\n\t\t\t\tnode.selectionSet ? [{ set: node.selectionSet, sure }] : [],\n\t\t\t),\n\t\t);\n\tif (isEnumType(type)) return enumSchema(type);\n\tconst builtIn = SCALARS[type.name];\n\treturn builtIn ? { type: builtIn } : {};\n}\n\nconst typeOf = (\n\twalk: Walk,\n\ttype: GraphQLOutputType,\n\tnodes: readonly Selected[],\n): JsonSchema =>\n\tisNonNullType(type)\n\t\t? shapeOf(walk, type.ofType, nodes)\n\t\t: nullable(shapeOf(walk, type, nodes));\n\n/**\n * The JSON Schema of a tool's result, `{ data, errors }`, from the selection\n * set of `operation`: nullable fields accept `null`, fragments are merged,\n * and on an interface or union the fields of a narrower fragment are\n * optional properties (no `anyOf` per concrete type). A field under `@skip`\n * or `@include` is optional. The document must be valid against `schema`.\n */\nexport function outputSchemaOf(\n\tschema: GraphQLSchema,\n\tdocument: DocumentNode,\n\toperation: OperationDefinitionNode,\n): JsonSchema {\n\tconst fragments = new Map<string, FragmentDefinitionNode>();\n\tfor (const definition of document.definitions)\n\t\tif (definition.kind === Kind.FRAGMENT_DEFINITION)\n\t\t\tfragments.set(definition.name.value, definition);\n\tconst root = schema.getRootType(operation.operation);\n\tconst data = root\n\t\t? nullable(\n\t\t\t\tobjectOf({ schema, fragments }, root, [\n\t\t\t\t\t{ set: operation.selectionSet, sure: true },\n\t\t\t\t]),\n\t\t\t)\n\t\t: {};\n\treturn { type: 'object', properties: { data, errors: ERRORS } };\n}\n",
|
|
38
|
+
"import { GraxiaConfigError } from '@graxia/core';\n\nconst EXCLUDE = 'or leave it out with operations.include';\n\n/** The longest tool name MCP allows. */\nexport const MAX_TOOL_NAME = 128;\n\n/** The boot problems of `operations`, each as what is wrong and what to write. */\nexport const problem = {\n\tmanifest: () =>\n\t\t'operations.documents is not a manifest. Fix: pass a Map, an object of id to source (persisted-documents.json), or an Apollo persisted query manifest.',\n\tsource: (id: string) =>\n\t\t`document \"${id}\" is not a GraphQL source string. Fix: map every id to the text of its document.`,\n\tparse: (id: string, message: string) =>\n\t\t`document \"${id}\" does not parse: ${message} Fix: regenerate the manifest; if it comes from another server's schema, do not pass it here.`,\n\tanonymous: (id: string) =>\n\t\t`document \"${id}\" holds an anonymous operation: a tool needs a name. Fix: name it (query BookById { ... }) and regenerate the manifest.`,\n\tinvalid: (\n\t\tnames: readonly string[],\n\t\tid: string,\n\t\tmessages: readonly string[],\n\t) =>\n\t\t`${names.join(', ')} (document \"${id}\") is not valid against the schema: ${messages.join(' ')} Fix: regenerate the manifest from the current schema, ${EXCLUDE}.`,\n\tintrospection: (names: readonly string[], id: string) =>\n\t\t`${names.join(', ')} (document \"${id}\") selects __schema or __type: introspection is not offered over MCP, an agent reads the schema with graphql_schema. Fix: leave the operation out with operations.include.`,\n\tincremental: (name: string, id: string, directive: string) =>\n\t\t`${name} (document \"${id}\") uses @${directive}, which is not available over MCP: a tool returns one complete result. Fix: remove @${directive}, ${EXCLUDE}.`,\n\tdescription: (name: string, id: string) =>\n\t\t`${name} (document \"${id}\") has no description: an agent picks a tool by its description. Fix: write one above the operation (\"\"\"Find a book by its id.\"\"\" query ${name} ...), or set operations.descriptions.${name}.`,\n\treserved: (name: string, id: string, tool: string) =>\n\t\t`${name} (document \"${id}\") gives the tool name ${tool}, and graphql_* names are the generic tools'. Fix: rename the operation, ${EXCLUDE}.`,\n\tduplicate: (tool: string, a: Named, b: Named) =>\n\t\t`${a.name} (document \"${a.id}\") and ${b.name} (document \"${b.id}\") both give the tool name ${tool}. Fix: rename one of them, ${EXCLUDE}.`,\n\ttooLong: (name: string, id: string, tool: string) =>\n\t\t`${name} (document \"${id}\") gives a tool name of ${tool.length} characters, and MCP allows ${MAX_TOOL_NAME}. Fix: rename the operation, ${EXCLUDE}.`,\n\tunusedDescription: (key: string, close: string | undefined) =>\n\t\t`operations.descriptions.${key} matches no operation of operations.documents${close ? ` (there is ${close}: names are case-sensitive)` : ''}. Fix: ${close ? `rename the key to ${close}` : 'remove the key, or name it after an operation of the manifest'}.`,\n\tempty: () =>\n\t\t'genericTools is false and operations gives no tool: an agent would have nothing to call. Fix: check operations.documents and operations.include (mutations need mutations: true), or remove genericTools: false.',\n};\n\ninterface Named {\n\tname: string;\n\tid: string;\n}\n\n/** One error for every problem found, so a manifest is fixed in one pass. */\nexport function operationsError(\n\tproblems: readonly string[],\n): GraxiaConfigError {\n\treturn new GraxiaConfigError(\n\t\t`createMcp: operations has ${problems.length} problem${problems.length === 1 ? '' : 's'}:\\n${problems.map((p) => `- ${p}`).join('\\n')}`,\n\t);\n}\n",
|
|
39
|
+
"import { validate } from 'graphql';\nimport { VIEW_RULES } from '../tools/operation';\nimport type { View } from '../view';\nimport type { OperationTool } from './types';\n\n/** The typed tools a caller may use: those whose operation is valid against the caller's view. */\nexport type VisibleTools = (view: View) => readonly OperationTool[];\n\n/**\n * Filters the tools by view, once per view: without `can` every caller\n * shares one view, so the list is computed once; with `can` once per request.\n */\nexport function createVisibleTools(\n\ttools: readonly OperationTool[],\n): VisibleTools {\n\tconst cache = new WeakMap<View, readonly OperationTool[]>();\n\treturn (view) => {\n\t\tlet visible = cache.get(view);\n\t\tif (!visible) {\n\t\t\tvisible = tools.filter(\n\t\t\t\t(tool) => validate(view.schema, tool.document, VIEW_RULES).length === 0,\n\t\t\t);\n\t\t\tcache.set(view, visible);\n\t\t}\n\t\treturn visible;\n\t};\n}\n",
|
|
40
|
+
"import type { Can } from '@graxia/core/agent';\nimport type { GraphQLSchema } from 'graphql';\nimport type { McpAuthInfo } from './auth/types';\nimport { buildView, type View } from './view';\n\n/** Builds the caller's view on first use, once per request: `fetch` asks for it only when the request lists or calls tools. */\nexport type ViewSource = (\n\trequest: Request,\n\tserverContext: object,\n\tauth: McpAuthInfo | undefined,\n) => () => Promise<View>;\n\n/**\n * Without `can` every caller sees the same schema, so the view is built once;\n * with `can` it is built once per request that needs it (`tools/list`,\n * `tools/call`), never for `initialize`, `ping` or a notification.\n */\nexport function createViewSource(\n\tschema: GraphQLSchema,\n\tcan:\n\t\t| ((\n\t\t\t\trequest: Request,\n\t\t\t\tserverContext: any,\n\t\t\t\tauth?: McpAuthInfo,\n\t\t ) => Can | Promise<Can>)\n\t\t| undefined,\n): ViewSource {\n\tlet shared: View | undefined;\n\tconst viewOf = async (\n\t\trequest: Request,\n\t\tserverContext: object,\n\t\tauth: McpAuthInfo | undefined,\n\t) => {\n\t\tif (can)\n\t\t\treturn buildView(\n\t\t\t\tschema,\n\t\t\t\tawait (auth\n\t\t\t\t\t? can(request, serverContext, auth)\n\t\t\t\t\t: can(request, serverContext)),\n\t\t\t);\n\t\tshared ??= buildView(schema);\n\t\treturn shared;\n\t};\n\treturn (request, serverContext, auth) => {\n\t\tlet pending: Promise<View> | undefined;\n\t\treturn () => {\n\t\t\tpending ??= viewOf(request, serverContext, auth);\n\t\t\treturn pending;\n\t\t};\n\t};\n}\n"
|
|
41
|
+
],
|
|
42
|
+
"mappings": ";AAAA;AAGA,IAAM,UAAU,IAAI;AAOb,SAAS,KAAQ,CAAC,MAA+B,IAAgB;AAAA,EACvE,OAAO,QAAQ,IAAI,MAAM,EAAE;AAAA;AAWrB,SAAS,OAAO,GAA4B;AAAA,EAClD,OAAO,QAAQ,SAAS;AAAA;;ACvBzB;;;ACGO,SAAS,OAAO,CACtB,QACA,SACA,KACA,UAAuB,CAAC,GACxB,MACW;AAAA,EACX,OAAO,SAAS,KACf;AAAA,IACC,SAAS;AAAA,IACT,OAAO;AAAA,MACN,MAAM;AAAA,MACN;AAAA,MACA,MAAM,SAAS,YAAY,EAAE,IAAI,IAAI,EAAE,MAAM,IAAI;AAAA,IAClD;AAAA,IACA,I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YAAY,SAAS;AAAA,QAC3B,MAAM,gBAAiB,KAAK,MAAM,CAAC;AAAA,QACnC,MAAM,QAAQ;AAAA,UACb;AAAA,UACA,OAAO,MAAM,YAAY,SAAS,OAAO;AAAA,UACzC,MAAM,MAAM,SAAS,SAAS,eAAe,SAAS;AAAA,QACvD;AAAA,QAEA,IAAI,QAAQ,aAAa,WAAW;AAAA,UACnC,MAAM,SAAS,MAAM,YACpB,MACA,WACA,MAAM,MAAM,QACZ,CAAC,SAAS,QAAQ,OAAO,MAAM,MAAM,IAAI,CAC1C;AAAA,UACA,IAAI;AAAA,YAAQ,OAAO,SAAS,QAAQ,IAAI;AAAA,QACzC;AAAA,QAEA,MAAM,WAAW,MAAM,QAAQ,IAAI,OAAO,MACzC,MAAM,WAAW,MAAM,QAAQ,MAAM,SAAS,OAAO,CAAC,CACvD;AAAA,QACA,OAAO,SAAS,UAAU,IAAI;AAAA,QAC7B,OAAO,OAAO;AAAA,QACf,QAAQ,KAAK;AAAA,QACb,OAAO,SACN,QACC,KACA,gDACA,qCACD,GACA,IACD;AAAA;AAAA;AAAA,IAGF,SAAS,MAAM,QAAQ,MAAM;AAAA,EAC9B;AAAA;",
|
|
43
|
+
"debugId": "FD985FEB20AF4DC164756E2164756E21",
|
|
44
|
+
"names": []
|
|
45
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type GraphQLSchema } from 'graphql';
|
|
2
|
+
import type { McpOperationsOptions, OperationTool } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Builds the typed tools of `operations`, once: one per named query of each
|
|
5
|
+
* document (and per mutation when `mutations` is on), with its input and
|
|
6
|
+
* output schemas.
|
|
7
|
+
* @throws {GraxiaConfigError} listing every problem, each with its fix.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildOperationTools(schema: GraphQLSchema, options: McpOperationsOptions, mutations: boolean): OperationTool[];
|
|
10
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/operations/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,aAAa,EAOlB,MAAM,SAAS,CAAC;AAOjB,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAqJnE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,oBAAoB,EAC7B,SAAS,EAAE,OAAO,GAChB,aAAa,EAAE,CAejB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Constraint } from '@graxia/core/agent';
|
|
2
|
+
import type { JsonSchema } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The schema `node` with the limits of `constraint`. On a list, `minItems`
|
|
5
|
+
* and `maxItems` go on the outermost array and the other limits on its
|
|
6
|
+
* innermost items; on a reference or a union nothing is added.
|
|
7
|
+
*/
|
|
8
|
+
export declare function constrained(node: JsonSchema, constraint: Constraint | undefined): JsonSchema;
|
|
9
|
+
/**
|
|
10
|
+
* One constraint a value must meet to satisfy all of `constraints` (a
|
|
11
|
+
* variable used at several arguments): the tightest bound of each kind;
|
|
12
|
+
* `pattern`, `format` and `multipleOf` are kept when the usages that declare
|
|
13
|
+
* one agree, and dropped when they differ (graxia's own checks still apply).
|
|
14
|
+
*/
|
|
15
|
+
export declare function tightest(constraints: readonly Constraint[]): Constraint | undefined;
|
|
16
|
+
//# sourceMappingURL=constraint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint.d.ts","sourceRoot":"","sources":["../../src/operations/constraint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAwC1C;;;;GAIG;AACH,wBAAgB,WAAW,CAC1B,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,UAAU,GAAG,SAAS,GAChC,UAAU,CASZ;AAYD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACvB,WAAW,EAAE,SAAS,UAAU,EAAE,GAChC,UAAU,GAAG,SAAS,CAgBxB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TrustedManifest } from '@graxia/core';
|
|
2
|
+
/** One document of a manifest. */
|
|
3
|
+
export interface ManifestEntry {
|
|
4
|
+
id: string;
|
|
5
|
+
source: unknown;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The documents of a manifest in any of core's three formats (a `Map`, an
|
|
9
|
+
* Apollo persisted query manifest, an object of id to source), in order.
|
|
10
|
+
* `undefined` when it is none of them. Sources are not checked here.
|
|
11
|
+
*/
|
|
12
|
+
export declare function manifestEntries(manifest: TrustedManifest | unknown): ManifestEntry[] | undefined;
|
|
13
|
+
//# sourceMappingURL=documents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"documents.d.ts","sourceRoot":"","sources":["../../src/operations/documents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,kCAAkC;AAClC,MAAM,WAAW,aAAa;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;CAChB;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,eAAe,GAAG,OAAO,GACjC,aAAa,EAAE,GAAG,SAAS,CAa7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type DocumentNode, type GraphQLSchema, type OperationDefinitionNode } from 'graphql';
|
|
2
|
+
import type { JsonSchema } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The JSON Schema (2020-12) of a tool's input: one property per variable of
|
|
5
|
+
* `operation`. A non-null variable without a default is required; a default
|
|
6
|
+
* goes to `default`; the description is the variable's own, else the one of
|
|
7
|
+
* the argument or input field it feeds; `@constraint` comes from input fields
|
|
8
|
+
* and, for a variable, from the arguments it is used at (the tightest when
|
|
9
|
+
* they differ). The document must be valid against `schema`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inputSchemaOf(schema: GraphQLSchema, document: DocumentNode, operation: OperationDefinitionNode): JsonSchema;
|
|
12
|
+
//# sourceMappingURL=input-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-schema.d.ts","sourceRoot":"","sources":["../../src/operations/input-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAEjB,KAAK,aAAa,EAElB,KAAK,uBAAuB,EAG5B,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,uBAAuB,GAChC,UAAU,CAgCZ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type GraphQLEnumType, type GraphQLInputType } from 'graphql';
|
|
2
|
+
import type { JsonSchema } from './types.js';
|
|
3
|
+
/** The `$defs` of one input schema: every input object the variables reach, by type name. Make it with {@link newDefs}. */
|
|
4
|
+
export type Defs = Record<string, JsonSchema>;
|
|
5
|
+
/** An empty {@link Defs}, without a prototype: a type may be named `constructor` or `toString`. */
|
|
6
|
+
export declare const newDefs: () => Defs;
|
|
7
|
+
/** The JSON type of each built-in scalar. */
|
|
8
|
+
export declare const SCALARS: Readonly<Record<string, string>>;
|
|
9
|
+
/** An enum as its value names; the description lists the values that have one. */
|
|
10
|
+
export declare function enumSchema(type: GraphQLEnumType): JsonSchema;
|
|
11
|
+
/** The same schema, accepting `null` too. */
|
|
12
|
+
export declare function nullable(node: JsonSchema): JsonSchema;
|
|
13
|
+
/**
|
|
14
|
+
* The JSON Schema of a GraphQL input type. Input objects go to `defs` and are
|
|
15
|
+
* referenced, so recursive types work; a nullable type also accepts `null`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function typeSchema(type: GraphQLInputType, defs: Defs): JsonSchema;
|
|
18
|
+
//# sourceMappingURL=input-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-type.d.ts","sourceRoot":"","sources":["../../src/operations/input-type.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,eAAe,EAGpB,KAAK,gBAAgB,EAOrB,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,2HAA2H;AAC3H,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE9C,mGAAmG;AACnG,eAAO,MAAM,OAAO,QAAO,IAAmC,CAAC;AAE/D,6CAA6C;AAC7C,eAAO,MAAM,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMpD,CAAC;AAKF,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU,CAW5D;AAED,6CAA6C;AAC7C,wBAAgB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAQrD;AAsED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,GAAG,UAAU,CAIzE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The tool name of an operation: its name in snake_case (`BookById` is `book_by_id`, `getHTTPStatus` is `get_http_status`). */
|
|
2
|
+
export declare function toolNameOf(operationName: string): string;
|
|
3
|
+
/** Tool names starting with this are the generic tools' (`graphql_schema`, `graphql_query`, `graphql_mutate`). */
|
|
4
|
+
export declare const RESERVED_PREFIX = "graphql_";
|
|
5
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/operations/naming.ts"],"names":[],"mappings":"AAAA,gIAAgI;AAChI,wBAAgB,UAAU,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED,kHAAkH;AAClH,eAAO,MAAM,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type DocumentNode, type GraphQLSchema, type OperationDefinitionNode } from 'graphql';
|
|
2
|
+
import type { JsonSchema } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The JSON Schema of a tool's result, `{ data, errors }`, from the selection
|
|
5
|
+
* set of `operation`: nullable fields accept `null`, fragments are merged,
|
|
6
|
+
* and on an interface or union the fields of a narrower fragment are
|
|
7
|
+
* optional properties (no `anyOf` per concrete type). A field under `@skip`
|
|
8
|
+
* or `@include` is optional. The document must be valid against `schema`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function outputSchemaOf(schema: GraphQLSchema, document: DocumentNode, operation: OperationDefinitionNode): JsonSchema;
|
|
11
|
+
//# sourceMappingURL=output-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-schema.d.ts","sourceRoot":"","sources":["../../src/operations/output-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,YAAY,EAKjB,KAAK,aAAa,EASlB,KAAK,uBAAuB,EAE5B,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AA2L1C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,uBAAuB,GAChC,UAAU,CAcZ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GraxiaConfigError } from '@graxia/core';
|
|
2
|
+
/** The longest tool name MCP allows. */
|
|
3
|
+
export declare const MAX_TOOL_NAME = 128;
|
|
4
|
+
/** The boot problems of `operations`, each as what is wrong and what to write. */
|
|
5
|
+
export declare const problem: {
|
|
6
|
+
manifest: () => string;
|
|
7
|
+
source: (id: string) => string;
|
|
8
|
+
parse: (id: string, message: string) => string;
|
|
9
|
+
anonymous: (id: string) => string;
|
|
10
|
+
invalid: (names: readonly string[], id: string, messages: readonly string[]) => string;
|
|
11
|
+
introspection: (names: readonly string[], id: string) => string;
|
|
12
|
+
incremental: (name: string, id: string, directive: string) => string;
|
|
13
|
+
description: (name: string, id: string) => string;
|
|
14
|
+
reserved: (name: string, id: string, tool: string) => string;
|
|
15
|
+
duplicate: (tool: string, a: Named, b: Named) => string;
|
|
16
|
+
tooLong: (name: string, id: string, tool: string) => string;
|
|
17
|
+
unusedDescription: (key: string, close: string | undefined) => string;
|
|
18
|
+
empty: () => string;
|
|
19
|
+
};
|
|
20
|
+
interface Named {
|
|
21
|
+
name: string;
|
|
22
|
+
id: string;
|
|
23
|
+
}
|
|
24
|
+
/** One error for every problem found, so a manifest is fixed in one pass. */
|
|
25
|
+
export declare function operationsError(problems: readonly string[]): GraxiaConfigError;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=problems.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problems.d.ts","sourceRoot":"","sources":["../../src/operations/problems.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIjD,wCAAwC;AACxC,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC,kFAAkF;AAClF,eAAO,MAAM,OAAO;;iBAGN,MAAM;gBAEP,MAAM,WAAW,MAAM;oBAEnB,MAAM;qBAGd,SAAS,MAAM,EAAE,MACpB,MAAM,YACA,SAAS,MAAM,EAAE;2BAGL,SAAS,MAAM,EAAE,MAAM,MAAM;wBAEhC,MAAM,MAAM,MAAM,aAAa,MAAM;wBAErC,MAAM,MAAM,MAAM;qBAErB,MAAM,MAAM,MAAM,QAAQ,MAAM;sBAE/B,MAAM,KAAK,KAAK,KAAK,KAAK;oBAE5B,MAAM,MAAM,MAAM,QAAQ,MAAM;6BAEvB,MAAM,SAAS,MAAM,GAAG,SAAS;;CAI1D,CAAC;AAEF,UAAU,KAAK;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACX;AAED,6EAA6E;AAC7E,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,SAAS,MAAM,EAAE,GACzB,iBAAiB,CAInB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { McpServer, StandardSchemaWithJSON } from '@modelcontextprotocol/server';
|
|
2
|
+
import { type ExecuteContext } from '../tools/execute.js';
|
|
3
|
+
import type { JsonSchema, OperationTool } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* A JSON Schema as the SDK takes it: advertised as it is, and accepting any
|
|
6
|
+
* value. The arguments are checked by graxia's own variable coercion, whose
|
|
7
|
+
* errors carry a code and a fix.
|
|
8
|
+
*/
|
|
9
|
+
export declare function advertised(schema: JsonSchema): StandardSchemaWithJSON<Record<string, unknown>>;
|
|
10
|
+
/** The fix of a variable graxia refused: an agent has the input schema, not the operation. */
|
|
11
|
+
export declare const ARGUMENTS_FIX = "Correct the arguments: see the tool's input schema.";
|
|
12
|
+
/** Registers the typed tools one caller may use on its per-request server. */
|
|
13
|
+
export declare function registerOperationTools(server: McpServer, tools: readonly OperationTool[], context: ExecuteContext): void;
|
|
14
|
+
/**
|
|
15
|
+
* The caller's view failed to build (`can` threw), so what the caller may
|
|
16
|
+
* use is unknown: a call to a typed tool answers the retry-later error of
|
|
17
|
+
* the other tools, not tool-not-found. For a request that does not list tools.
|
|
18
|
+
*/
|
|
19
|
+
export declare function registerFailedTools(server: McpServer, tools: readonly OperationTool[]): void;
|
|
20
|
+
//# sourceMappingURL=register.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../src/operations/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,SAAS,EACT,sBAAsB,EACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,cAAc,EAAW,MAAM,kBAAkB,CAAC;AAGhE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,UAAU,GAChB,sBAAsB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CASjD;AAED,8FAA8F;AAC9F,eAAO,MAAM,aAAa,wDAC4B,CAAC;AA+CvD,8EAA8E;AAC9E,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,SAAS,aAAa,EAAE,EAC/B,OAAO,EAAE,cAAc,GACrB,IAAI,CA4BN;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,SAAS,aAAa,EAAE,GAC7B,IAAI,CAON"}
|