@anyknown/mcp 0.1.4 → 0.3.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.
Files changed (108) hide show
  1. package/README.md +33 -2
  2. package/dist/catalog/types.d.ts +10 -0
  3. package/dist/client/constants.d.ts +3 -0
  4. package/dist/client/handshake.d.ts +2 -0
  5. package/dist/client/headers-for.d.ts +2 -0
  6. package/dist/client/index.d.ts +6 -0
  7. package/dist/client/joined-data-lines.d.ts +1 -0
  8. package/dist/client/message-matching-id.d.ts +2 -0
  9. package/dist/client/notify.d.ts +2 -0
  10. package/dist/client/parse-body.d.ts +2 -0
  11. package/dist/client/parse-challenge.d.ts +2 -0
  12. package/dist/client/read-sse.d.ts +2 -0
  13. package/dist/client/rpc.d.ts +2 -0
  14. package/dist/client/send.d.ts +2 -0
  15. package/dist/client/types.d.ts +25 -0
  16. package/dist/errors.d.ts +1 -1
  17. package/dist/portable/apply-auth.d.ts +5 -0
  18. package/dist/portable/args-errors.d.ts +2 -0
  19. package/dist/portable/call-tool.d.ts +6 -0
  20. package/dist/portable/constants.d.ts +17 -0
  21. package/dist/portable/fetch-document.d.ts +1 -0
  22. package/dist/portable/graphql/args-schema.d.ts +5 -0
  23. package/dist/portable/graphql/call-graphql.d.ts +2 -0
  24. package/dist/portable/graphql/constants.d.ts +15 -0
  25. package/dist/portable/graphql/default-selection.d.ts +2 -0
  26. package/dist/portable/graphql/field-tool.d.ts +4 -0
  27. package/dist/portable/graphql/index.d.ts +2 -0
  28. package/dist/portable/graphql/input-defs.d.ts +2 -0
  29. package/dist/portable/graphql/input-schema.d.ts +2 -0
  30. package/dist/portable/graphql/introspect.d.ts +3 -0
  31. package/dist/portable/graphql/introspected-schema.d.ts +2 -0
  32. package/dist/portable/graphql/json-of.d.ts +1 -0
  33. package/dist/portable/graphql/or-null.d.ts +1 -0
  34. package/dist/portable/graphql/post-graphql.d.ts +2 -0
  35. package/dist/portable/graphql/query-document.d.ts +2 -0
  36. package/dist/portable/graphql/read-graphql.d.ts +6 -0
  37. package/dist/portable/graphql/schema.d.ts +14 -0
  38. package/dist/portable/graphql/sdl-schema.d.ts +2 -0
  39. package/dist/portable/graphql/single-root-field.d.ts +3 -0
  40. package/dist/portable/graphql/type-schema.d.ts +3 -0
  41. package/dist/portable/graphql/types.d.ts +9 -0
  42. package/dist/portable/index.d.ts +15 -0
  43. package/dist/portable/mcp/call-mcp-tool.d.ts +6 -0
  44. package/dist/portable/mcp/index.d.ts +4 -0
  45. package/dist/portable/mcp/list-mcp-tools.d.ts +7 -0
  46. package/dist/portable/mcp/mcp-request.d.ts +6 -0
  47. package/dist/portable/mcp/schema.d.ts +11 -0
  48. package/dist/portable/mcp/types.d.ts +4 -0
  49. package/dist/portable/oauth/authorize-url.d.ts +7 -0
  50. package/dist/portable/oauth/b64url.d.ts +1 -0
  51. package/dist/portable/oauth/capped-json.d.ts +1 -0
  52. package/dist/portable/oauth/client-basic.d.ts +1 -0
  53. package/dist/portable/oauth/constants.d.ts +1 -0
  54. package/dist/portable/oauth/discover.d.ts +3 -0
  55. package/dist/portable/oauth/exchange-code.d.ts +9 -0
  56. package/dist/portable/oauth/get-json.d.ts +2 -0
  57. package/dist/portable/oauth/index.d.ts +11 -0
  58. package/dist/portable/oauth/issuer-mismatch.d.ts +1 -0
  59. package/dist/portable/oauth/metadata-urls.d.ts +1 -0
  60. package/dist/portable/oauth/pick-scope.d.ts +2 -0
  61. package/dist/portable/oauth/pkce.d.ts +4 -0
  62. package/dist/portable/oauth/post-token.d.ts +2 -0
  63. package/dist/portable/oauth/protected-resource-url.d.ts +1 -0
  64. package/dist/portable/oauth/random-state.d.ts +1 -0
  65. package/dist/portable/oauth/read-metadata.d.ts +8 -0
  66. package/dist/portable/oauth/refresh-tokens.d.ts +7 -0
  67. package/dist/portable/oauth/register-client.d.ts +2 -0
  68. package/dist/portable/oauth/schema.d.ts +20 -0
  69. package/dist/portable/oauth/types.d.ts +12 -0
  70. package/dist/portable/openapi/annotations-for.d.ts +4 -0
  71. package/dist/portable/openapi/append-params.d.ts +1 -0
  72. package/dist/portable/openapi/call-openapi.d.ts +2 -0
  73. package/dist/portable/openapi/collect-defs.d.ts +2 -0
  74. package/dist/portable/openapi/constants.d.ts +6 -0
  75. package/dist/portable/openapi/discovered-oauth.d.ts +2 -0
  76. package/dist/portable/openapi/has-cyclic-alias.d.ts +2 -0
  77. package/dist/portable/openapi/index.d.ts +2 -0
  78. package/dist/portable/openapi/input-schema.d.ts +2 -0
  79. package/dist/portable/openapi/merged-parameters.d.ts +2 -0
  80. package/dist/portable/openapi/operation-tool.d.ts +3 -0
  81. package/dist/portable/openapi/operations-of.d.ts +2 -0
  82. package/dist/portable/openapi/param-group.d.ts +2 -0
  83. package/dist/portable/openapi/parse-document.d.ts +2 -0
  84. package/dist/portable/openapi/path-segment.d.ts +1 -0
  85. package/dist/portable/openapi/read-openapi.d.ts +6 -0
  86. package/dist/portable/openapi/request-body-schema.d.ts +2 -0
  87. package/dist/portable/openapi/request-body.d.ts +5 -0
  88. package/dist/portable/openapi/request-headers.d.ts +2 -0
  89. package/dist/portable/openapi/request-url.d.ts +2 -0
  90. package/dist/portable/openapi/resolve-ref.d.ts +1 -0
  91. package/dist/portable/openapi/rewrite-refs.d.ts +1 -0
  92. package/dist/portable/openapi/schema.d.ts +66 -0
  93. package/dist/portable/openapi/spec-defaults.d.ts +3 -0
  94. package/dist/portable/openapi/tool-name.d.ts +1 -0
  95. package/dist/portable/openapi/types.d.ts +27 -0
  96. package/dist/portable/openapi/unique-names.d.ts +1 -0
  97. package/dist/portable/openapi/yaml-value.d.ts +1 -0
  98. package/dist/portable/read-capped.d.ts +4 -0
  99. package/dist/portable/read-tools.d.ts +2 -0
  100. package/dist/portable/stale-tool-names.d.ts +2 -0
  101. package/dist/portable/text-result.d.ts +5 -0
  102. package/dist/portable/tool-rows-of.d.ts +2 -0
  103. package/dist/portable/types.d.ts +93 -0
  104. package/dist/public.d.ts +2 -2
  105. package/dist/rpc/hub-rpc.d.ts +7 -6
  106. package/dist/rpc/types.d.ts +47 -2
  107. package/dist/schema.d.ts +13 -11
  108. package/package.json +5 -1
package/README.md CHANGED
@@ -1,10 +1,41 @@
1
1
  # anyknown/mcp
2
2
 
3
- The MCP hub: the directory of MCP servers (admin catalogue plus each user's own `own_*` servers), the MCP client, OAuth (discovery, dynamic registration, PKCE, refresh), per-user credentials and the tool cache.
3
+ The hub: the directory of servers (admin catalogue plus each user's own `own_*` servers), per-user credentials, the tool cache, and the adapters that read and call a server by its `kind`. An `mcp` server is an MCP server (its `tools/list` tools); an `openapi` server is an HTTP API described by an OpenAPI document (each operation is a tool); a `graphql` server is a GraphQL endpoint (each Query and Mutation root field is a tool). Every tool is named `<server_id>/<name>` and goes through the same search, describe and call. The admin catalogue holds only `mcp` servers. The adapters live in `src/portable/` and use only the `fetch` passed to them.
4
+
5
+ Each server has one `auth`: `none`, `bearer`, `api_key` (a header or query parameter whose name comes with create or from the spec's `apiKey` security scheme), `basic` or `oauth`; `mcp` servers take only `oauth`, `bearer` and `none`. OAuth always uses PKCE and product's `/api/mcp/callback` as the redirect URI:
6
+
7
+ - `mcp` discovers the authorization server from the 401 challenge's resource metadata (or the server's well-known protected resource URL), identifies itself with a client ID metadata document when the server supports it and dynamic registration otherwise, sends `resource`, and rediscovers on refresh.
8
+ - `openapi` and `graphql` use the user's own OAuth app. The client id and optional client secret come with connect; the authorize and token endpoints and the scopes come with create, or else from the spec's `oauth2` authorization code flow or its `openIdConnect` discovery document, and it is `invalid` when neither has them. The hub sends no `resource`, doesn't check `iss` (there is no issuer to compare), authenticates with `client_secret_basic` when there is a secret, and refreshes against the stored token endpoint without discovery.
4
9
 
5
10
  It has no public URL. The only way in is product's `MCP` service binding, which calls the `Hub` `WorkerEntrypoint` over RPC (`src/rpc/`). Product owns authentication, scope checks (`mcp:use`, `product:admin`), request validation, activity and the OAuth cookie; the hub trusts the `userId` product passes.
6
11
 
7
- Tokens are sealed to the user's public key and opened only through product's `KeyringMcp` entrypoint (`KEYRING`, a service binding to `product` / `product-staging` that exposes only `seal` / `open` for kind `mcp`), so that entrypoint has to be deployed before this worker. A locked Keyring is `key_locked` (423); a user with no public key yet is `no_user_key` (409).
12
+ Tokens, API keys, basic credentials and OAuth client secrets are sealed to the user's public key under the server id and opened only through product's `KeyringMcp` entrypoint (`KEYRING`, a service binding to `product` / `product-staging` that exposes only `seal` / `open` for kind `mcp`), so that entrypoint has to be deployed before this worker. The OAuth cookie carries the client id and, when connect brings a new client, its secret sealed the same way (never in the clear); the hub opens it itself when it exchanges the code, and saves the client with the credential only once the sign-in completes, so an abandoned sign-in leaves the working client alone. A refresh sends the saved secret only when it belongs to the credential's client id. Disconnecting or removing a server drops its OAuth client along with its credential. A locked Keyring is `key_locked` (423); a user with no public key yet is `no_user_key` (409).
13
+
14
+ ## Where tools come from
15
+
16
+ `spec_url` is where the hub reads a server's tools: an `openapi` server's spec URL, a `graphql` server's endpoint (introspection), or `null` when the tools come from an uploaded document (an OpenAPI document or GraphQL SDL). `mcp` servers always have `null` and read `tools/list`.
17
+
18
+ - `openapi` servers, uploaded `graphql` ones and introspected `graphql` ones with `none`, `bearer`, `api_key` or `basic` are read at create, the last with the credentials sent along with it. The server row, its tools and the sealed credential are written in one batch after the read succeeds; a failed read returns its error and writes nothing. `mcp` servers and introspected `graphql` ones with `oauth` are read after connect, the OAuth ones in the callback once the code is exchanged.
19
+ - Connect, or for OAuth its callback, re-reads servers that have a `spec_url` and `mcp` servers, and a failed re-read doesn't fail it; uploaded ones aren't re-read and return their current tool count. An introspected `graphql` server is the exception: it is read with the new credentials first, and they are stored only when that read succeeds, so a failed connect keeps the old ones.
20
+ - Refresh without `document` re-reads servers that have a `spec_url` and `mcp` servers, and is `invalid` for uploaded ones. Refresh with `document` reads the upload instead, without credentials, so it works before the server is connected; when that read succeeds `spec_url` becomes `null`, whatever it was, and the server reads from uploads from then on. An `mcp` server with `document` is `invalid`.
21
+ - Introspection turned off means uploading SDL. An introspection answer that is a GraphQL response (JSON with `errors` and no `data.__schema`) is `no_introspection` (412) whatever its status; an upstream 401 is `mcp_not_connected` (412); anything else is `mcp_upstream_error` (502). Such a server never gets connected: create writes nothing, connect keeps the old credentials, and the OAuth callback drops the new token while the server row stays. Uploading the SDL with refresh sets `spec_url` to `null`, after which the OAuth callback no longer introspects.
22
+ - Every read stores how many operations or root fields it skipped in `mcp_server.dropped`, even when it found no tools: OpenAPI operations it can't call (a required cookie parameter, a body that is neither JSON nor a form, a body on GET or HEAD), input schemas over 64 KB, and everything past 500 tools.
23
+ - A read that finds no tools writes no tool rows. Otherwise, on the user's own servers (every `openapi` and `graphql` server, and the `mcp` servers they added) the sync upserts the tools it read and deletes the ones that vanished, only rows owned by that user, up to 90 names per statement. Catalogue servers' tools are shared by everyone, so their sync only upserts.
24
+
25
+ ## Outbound fetch
26
+
27
+ Every request the hub sends goes through `guardedFetch` (`src/guard/`): MCP calls, spec and discovery documents, introspection, API calls, and OAuth discovery, registration, code exchange and refresh. It allows only `https`, refuses `anyknown.com`, `anyknown.app` and their subdomains (`invalid`, 400), and follows redirects itself: up to 3 same-origin hops, checking each one again. A cross-origin redirect, or a fourth one, comes back to the caller as the 3xx, so credentials never reach another origin. Create checks `url` and `spec_url` the same way before it fetches anything, and the OAuth endpoints before it writes anything.
28
+
29
+ Documents over these sizes are `invalid` (400), whether fetched or uploaded:
30
+
31
+ | Document | Limit |
32
+ | --------------------------------- | ------ |
33
+ | OpenAPI as JSON (starts with `{`) | 4 MB |
34
+ | OpenAPI as YAML | 512 KB |
35
+ | GraphQL SDL | 512 KB |
36
+ | Introspection answer | 8 MB |
37
+
38
+ `openapi` and `graphql` call results keep the first 50 KB of the body and say where they were cut.
8
39
 
9
40
  ## Environments
10
41
 
@@ -1,3 +1,4 @@
1
+ import type { UpstreamAuth } from "../portable";
1
2
  import type { McpConnectionStatus, McpServerRow, McpToolRow } from "../schema";
2
3
  export type CatalogServer = McpServerRow & {
3
4
  tool_count: number;
@@ -19,3 +20,12 @@ export type HitRow = {
19
20
  description: string;
20
21
  };
21
22
  export type ToolListing = Pick<McpToolRow, "name" | "title" | "description" | "annotations">;
23
+ export type SyncOptions = {
24
+ document?: string;
25
+ auth?: UpstreamAuth;
26
+ fetchImpl?: typeof fetch;
27
+ };
28
+ export type SyncResult = {
29
+ tools: number;
30
+ dropped: number;
31
+ };
@@ -0,0 +1,3 @@
1
+ export declare const PROTOCOL_VERSION = "2026-07-28";
2
+ export declare const DEFAULT_TIMEOUT_MS = 30000;
3
+ export declare const MAX_TIMEOUT_MS = 120000;
@@ -0,0 +1,2 @@
1
+ import type { Handshake, Transport } from "./types";
2
+ export declare function handshake(t: Transport): Promise<Handshake>;
@@ -0,0 +1,2 @@
1
+ import type { Transport } from "./types";
2
+ export declare function headersFor(t: Transport): Headers;
@@ -0,0 +1,6 @@
1
+ export { DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS, PROTOCOL_VERSION } from "./constants";
2
+ export { handshake } from "./handshake";
3
+ export { notify } from "./notify";
4
+ export { parseChallenge } from "./parse-challenge";
5
+ export { rpc } from "./rpc";
6
+ export type { Handshake, RpcResult, Transport } from "./types";
@@ -0,0 +1 @@
1
+ export declare function joinedDataLines(block: string): string;
@@ -0,0 +1,2 @@
1
+ import type { JsonRpcMessage } from "./types";
2
+ export declare function messageMatchingId(raw: string, id: number): JsonRpcMessage | null;
@@ -0,0 +1,2 @@
1
+ import type { Transport } from "./types";
2
+ export declare function notify(t: Transport, method: string): Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { JsonRpcMessage } from "./types";
2
+ export declare function parseBody(response: Response, id: number): Promise<JsonRpcMessage>;
@@ -0,0 +1,2 @@
1
+ import type { AuthChallenge } from "../errors";
2
+ export declare function parseChallenge(header: string | null): AuthChallenge;
@@ -0,0 +1,2 @@
1
+ import type { JsonRpcMessage } from "./types";
2
+ export declare function readSse(response: Response, id: number): Promise<JsonRpcMessage>;
@@ -0,0 +1,2 @@
1
+ import type { RpcResult, Transport } from "./types";
2
+ export declare function rpc(t: Transport, method: string, params?: Record<string, unknown>): Promise<RpcResult>;
@@ -0,0 +1,2 @@
1
+ import type { Transport } from "./types";
2
+ export declare function send(t: Transport, payload: unknown): Promise<Response>;
@@ -0,0 +1,25 @@
1
+ export type Transport = {
2
+ url: string;
3
+ token?: string | null;
4
+ sessionId?: string | null;
5
+ protocolVersion?: string | null;
6
+ timeoutMs?: number;
7
+ fetchImpl?: typeof fetch;
8
+ };
9
+ export type RpcResult = {
10
+ result: unknown;
11
+ sessionId: string | null;
12
+ };
13
+ export type JsonRpcMessage = {
14
+ jsonrpc?: string;
15
+ id?: number | string | null;
16
+ result?: unknown;
17
+ error?: {
18
+ code?: number;
19
+ message?: string;
20
+ };
21
+ };
22
+ export type Handshake = {
23
+ sessionId: string | null;
24
+ protocolVersion: string | null;
25
+ };
package/dist/errors.d.ts CHANGED
@@ -2,7 +2,7 @@ export type AuthChallenge = {
2
2
  resourceMetadata: string | null;
3
3
  scope: string | null;
4
4
  };
5
- export type McpErrorCode = "invalid" | "not_found" | "mcp_not_connected" | "mcp_upstream_error" | "no_user_key" | "key_locked";
5
+ export type McpErrorCode = "invalid" | "not_found" | "mcp_not_connected" | "mcp_upstream_error" | "no_introspection" | "no_user_key" | "key_locked";
6
6
  export declare class McpError extends Error {
7
7
  readonly code: McpErrorCode;
8
8
  readonly status: 400 | 404 | 409 | 412 | 423 | 502;
@@ -0,0 +1,5 @@
1
+ import type { UpstreamAuth } from "./types";
2
+ export declare function applyAuth(auth: UpstreamAuth, target: string | URL, init?: HeadersInit): {
3
+ url: URL;
4
+ headers: Headers;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { OutputUnit } from "@cfworker/json-schema";
2
+ export declare function argsErrors(errors: OutputUnit[]): string;
@@ -0,0 +1,6 @@
1
+ import { type McpSession } from "./mcp";
2
+ import type { CallToolInput } from "./types";
3
+ export declare function callTool(input: CallToolInput): Promise<{
4
+ result: unknown;
5
+ session: McpSession;
6
+ }>;
@@ -0,0 +1,17 @@
1
+ import type { McpSession } from "./mcp/types";
2
+ export declare const KINDS: readonly ["mcp", "openapi", "graphql"];
3
+ export declare const RESULT_TEXT_MAX = 50000;
4
+ export declare const JSON_MAX_BYTES = 4000000;
5
+ export declare const YAML_MAX_BYTES = 512000;
6
+ export declare const SDL_MAX_BYTES = 512000;
7
+ export declare const INTROSPECTION_MAX_BYTES = 8000000;
8
+ export declare const OAUTH_JSON_MAX_BYTES = 1000000;
9
+ export declare const TOOLS_MAX = 500;
10
+ export declare const INPUT_SCHEMA_MAX = 64000;
11
+ export declare const DESCRIPTION_MAX = 1000;
12
+ export declare const TOOL_NAME_MAX = 64;
13
+ export declare const ARG_ERRORS_MAX = 5;
14
+ export declare const SUMMARY_KEYWORDS: Set<string>;
15
+ export declare const DELETE_BATCH = 90;
16
+ export declare const MAX_PAGES = 20;
17
+ export declare const NO_SESSION: McpSession;
@@ -0,0 +1 @@
1
+ export declare function fetchDocument(url: string, fetchImpl: typeof fetch, max: number): Promise<string>;
@@ -0,0 +1,5 @@
1
+ import { type GraphQLArgument, type GraphQLInputField } from "graphql";
2
+ import type { UsedTypes } from "./types";
3
+ type InputValue = GraphQLArgument | GraphQLInputField;
4
+ export declare function argsSchema(values: readonly InputValue[], used: UsedTypes): Record<string, unknown>;
5
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { GraphqlCall, ToolResult, Upstream } from "../types";
2
+ export declare function callGraphql(upstream: Upstream, call: GraphqlCall, inputSchema: unknown, args: unknown): Promise<ToolResult>;
@@ -0,0 +1,15 @@
1
+ export declare const SCALAR_SCHEMAS: Map<string, Record<string, unknown>>;
2
+ export declare const OPERATION_ANNOTATIONS: {
3
+ query: {
4
+ readOnlyHint: boolean;
5
+ destructiveHint: boolean;
6
+ };
7
+ mutation: {
8
+ readOnlyHint: boolean;
9
+ destructiveHint: boolean;
10
+ };
11
+ };
12
+ export declare const GRAPHQL_HEADERS: {
13
+ "content-type": string;
14
+ accept: string;
15
+ };
@@ -0,0 +1,2 @@
1
+ import { type GraphQLOutputType } from "graphql";
2
+ export declare function defaultSelection(type: GraphQLOutputType): string;
@@ -0,0 +1,4 @@
1
+ import type { GraphQLField } from "graphql";
2
+ import type { UpstreamTool } from "../types";
3
+ import type { GraphqlOperation } from "./types";
4
+ export declare function fieldTool(operation: GraphqlOperation, field: GraphQLField<unknown, unknown>): UpstreamTool | null;
@@ -0,0 +1,2 @@
1
+ export { callGraphql } from "./call-graphql";
2
+ export { readGraphql } from "./read-graphql";
@@ -0,0 +1,2 @@
1
+ import type { UsedTypes } from "./types";
2
+ export declare function inputDefs(used: UsedTypes): Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ import { type GraphQLField } from "graphql";
2
+ export declare function inputSchema(field: GraphQLField<unknown, unknown>, selection: string): Record<string, unknown>;
@@ -0,0 +1,3 @@
1
+ import { type GraphQLSchema } from "graphql";
2
+ import type { Upstream } from "../types";
3
+ export declare function introspect(upstream: Upstream): Promise<GraphQLSchema>;
@@ -0,0 +1,2 @@
1
+ import { type GraphQLSchema } from "graphql";
2
+ export declare function introspectedSchema(response: Response, text: string): GraphQLSchema;
@@ -0,0 +1 @@
1
+ export declare function jsonOf(text: string): unknown;
@@ -0,0 +1 @@
1
+ export declare function orNull(schema: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ import type { Upstream } from "../types";
2
+ export declare function postGraphql(upstream: Upstream, body: unknown): Promise<Response>;
@@ -0,0 +1,2 @@
1
+ import type { GraphqlCall } from "../types";
2
+ export declare function queryDocument(call: GraphqlCall, args: Record<string, unknown>, selection: string): string;
@@ -0,0 +1,6 @@
1
+ import type { ReadResult, Upstream } from "../types";
2
+ export declare function readGraphql(source: {
3
+ document: string;
4
+ } | {
5
+ introspect: Upstream;
6
+ }): Promise<ReadResult>;
@@ -0,0 +1,14 @@
1
+ import type { IntrospectionSchema } from "graphql";
2
+ import { z } from "zod";
3
+ export declare const introspectionAnswerSchema: z.ZodObject<{
4
+ data: z.ZodObject<{
5
+ __schema: z.ZodCustom<IntrospectionSchema, IntrospectionSchema>;
6
+ }, z.core.$strip>;
7
+ }, z.core.$strip>;
8
+ export declare const errorsAnswerSchema: z.ZodObject<{
9
+ errors: z.ZodArray<z.ZodUnknown>;
10
+ }, z.core.$strip>;
11
+ export declare const failedAnswerSchema: z.ZodObject<{
12
+ errors: z.ZodArray<z.ZodUnknown>;
13
+ data: z.ZodOptional<z.ZodNull>;
14
+ }, z.core.$strip>;
@@ -0,0 +1,2 @@
1
+ import { type GraphQLSchema } from "graphql";
2
+ export declare function sdlSchema(document: string): GraphQLSchema;
@@ -0,0 +1,3 @@
1
+ import { type FieldNode } from "graphql";
2
+ import type { GraphqlCall } from "../types";
3
+ export declare function singleRootField(query: string, call: GraphqlCall): FieldNode | null;
@@ -0,0 +1,3 @@
1
+ import { type GraphQLInputType } from "graphql";
2
+ import type { UsedTypes } from "./types";
3
+ export declare function typeSchema(type: GraphQLInputType, used: UsedTypes): Record<string, unknown>;
@@ -0,0 +1,9 @@
1
+ import type { GraphQLEnumType, GraphQLField, GraphQLInputObjectType } from "graphql";
2
+ import type { GraphqlCall } from "../types";
3
+ export type GraphqlOperation = GraphqlCall["operation"];
4
+ export type RootField = [GraphqlOperation, GraphQLField<unknown, unknown>];
5
+ export type UsedTypes = Map<string, GraphQLEnumType | GraphQLInputObjectType>;
6
+ export type GraphqlArgs = {
7
+ args?: Record<string, unknown>;
8
+ selection?: string;
9
+ };
@@ -0,0 +1,15 @@
1
+ export { applyAuth } from "./apply-auth";
2
+ export { callTool } from "./call-tool";
3
+ export { ARG_ERRORS_MAX, DELETE_BATCH, DESCRIPTION_MAX, INPUT_SCHEMA_MAX, INTROSPECTION_MAX_BYTES, JSON_MAX_BYTES, KINDS, MAX_PAGES, NO_SESSION, OAUTH_JSON_MAX_BYTES, RESULT_TEXT_MAX, SDL_MAX_BYTES, TOOL_NAME_MAX, TOOLS_MAX, YAML_MAX_BYTES, } from "./constants";
4
+ export { callGraphql, readGraphql } from "./graphql";
5
+ export { callMcpTool, listMcpTools, mcpRequest } from "./mcp";
6
+ export type { McpSession } from "./mcp";
7
+ export { callOpenApi, readOpenApi } from "./openapi";
8
+ export { authorizeUrl, discover, exchangeCode, issuerMismatch, pkce, randomState, refreshTokens, registerClient, } from "./oauth";
9
+ export type { Discovery, Tokens } from "./oauth";
10
+ export { readCapped } from "./read-capped";
11
+ export { readTools } from "./read-tools";
12
+ export { staleToolNames } from "./stale-tool-names";
13
+ export { textResult } from "./text-result";
14
+ export { toolRowsOf } from "./tool-rows-of";
15
+ export type { CallToolInput, GraphqlCall, McpKind, OpenApiCall, ReadResult, ReadToolsInput, SpecDefaults, ToolResult, ToolRow, Upstream, UpstreamAuth, UpstreamTool, } from "./types";
@@ -0,0 +1,6 @@
1
+ import type { Upstream } from "../types";
2
+ import type { McpSession } from "./types";
3
+ export declare function callMcpTool(upstream: Upstream, session: McpSession, name: string, args: unknown): Promise<{
4
+ result: unknown;
5
+ session: McpSession;
6
+ }>;
@@ -0,0 +1,4 @@
1
+ export { callMcpTool } from "./call-mcp-tool";
2
+ export { listMcpTools } from "./list-mcp-tools";
3
+ export { mcpRequest } from "./mcp-request";
4
+ export type { McpSession } from "./types";
@@ -0,0 +1,7 @@
1
+ import type { Upstream, UpstreamTool } from "../types";
2
+ import type { McpSession } from "./types";
3
+ export declare function listMcpTools(upstream: Upstream, session: McpSession): Promise<{
4
+ tools: UpstreamTool[];
5
+ session: McpSession;
6
+ complete: boolean;
7
+ }>;
@@ -0,0 +1,6 @@
1
+ import type { Upstream } from "../types";
2
+ import type { McpSession } from "./types";
3
+ export declare function mcpRequest(upstream: Upstream, session: McpSession, method: string, params?: Record<string, unknown>): Promise<{
4
+ result: unknown;
5
+ session: McpSession;
6
+ }>;
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ export declare const toolsListSchema: z.ZodObject<{
3
+ tools: z.ZodArray<z.ZodObject<{
4
+ name: z.ZodString;
5
+ title: z.ZodOptional<z.ZodString>;
6
+ description: z.ZodOptional<z.ZodString>;
7
+ inputSchema: z.ZodOptional<z.ZodUnknown>;
8
+ annotations: z.ZodOptional<z.ZodUnknown>;
9
+ }, z.core.$strip>>;
10
+ nextCursor: z.ZodOptional<z.ZodString>;
11
+ }, z.core.$strip>;
@@ -0,0 +1,4 @@
1
+ export type McpSession = {
2
+ sessionId: string | null;
3
+ protocolVersion: string | null;
4
+ };
@@ -0,0 +1,7 @@
1
+ import type { Discovery } from "./types";
2
+ export declare function authorizeUrl(discovery: Discovery, args: {
3
+ clientId: string;
4
+ redirectUri: string;
5
+ state: string;
6
+ challenge: string;
7
+ }): string;
@@ -0,0 +1 @@
1
+ export declare const b64url: (bytes: Uint8Array) => string;
@@ -0,0 +1 @@
1
+ export declare function cappedJson(response: Response): Promise<unknown>;
@@ -0,0 +1 @@
1
+ export declare function clientBasic(clientId: string, clientSecret: string | null | undefined): string | null;
@@ -0,0 +1 @@
1
+ export declare const TIMEOUT_MS = 10000;
@@ -0,0 +1,3 @@
1
+ import { type AuthChallenge } from "../../errors";
2
+ import type { Discovery } from "./types";
3
+ export declare function discover(serverUrl: string, challenge: AuthChallenge | null, fetchImpl?: typeof fetch): Promise<Discovery>;
@@ -0,0 +1,9 @@
1
+ import type { Discovery, Tokens } from "./types";
2
+ export declare function exchangeCode(args: {
3
+ discovery: Discovery;
4
+ clientId: string;
5
+ clientSecret?: string | null;
6
+ redirectUri: string;
7
+ code: string;
8
+ verifier: string;
9
+ }, fetchImpl?: typeof fetch): Promise<Tokens>;
@@ -0,0 +1,2 @@
1
+ import type { z } from "zod";
2
+ export declare function getJson<T>(url: string, schema: z.ZodType<T>, fetchImpl: typeof fetch): Promise<T | null>;
@@ -0,0 +1,11 @@
1
+ export { authorizeUrl } from "./authorize-url";
2
+ export { discover } from "./discover";
3
+ export { exchangeCode } from "./exchange-code";
4
+ export { issuerMismatch } from "./issuer-mismatch";
5
+ export { metadataUrls } from "./metadata-urls";
6
+ export { pkce } from "./pkce";
7
+ export { protectedResourceUrl } from "./protected-resource-url";
8
+ export { randomState } from "./random-state";
9
+ export { refreshTokens } from "./refresh-tokens";
10
+ export { registerClient } from "./register-client";
11
+ export type { Discovery, Tokens } from "./types";
@@ -0,0 +1 @@
1
+ export declare function issuerMismatch(expected: string, iss: string | null | undefined): boolean;
@@ -0,0 +1 @@
1
+ export declare function metadataUrls(issuer: string): string[];
@@ -0,0 +1,2 @@
1
+ import type { AuthChallenge } from "../../errors";
2
+ export declare function pickScope(challenge: AuthChallenge | null, advertised: string[] | undefined): string | null;
@@ -0,0 +1,4 @@
1
+ export declare function pkce(): Promise<{
2
+ verifier: string;
3
+ challenge: string;
4
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { Tokens } from "./types";
2
+ export declare function postToken(tokenEndpoint: string, form: URLSearchParams, fetchImpl: typeof fetch, authorization?: string | null): Promise<Tokens>;
@@ -0,0 +1 @@
1
+ export declare function protectedResourceUrl(resource: string): string;
@@ -0,0 +1 @@
1
+ export declare function randomState(): string;
@@ -0,0 +1,8 @@
1
+ export declare function readMetadata(issuer: string, fetchImpl: typeof fetch): Promise<{
2
+ issuer: string;
3
+ authorization_endpoint: string;
4
+ token_endpoint: string;
5
+ registration_endpoint?: string | undefined;
6
+ scopes_supported?: string[] | undefined;
7
+ client_id_metadata_document_supported?: boolean | undefined;
8
+ } | null>;
@@ -0,0 +1,7 @@
1
+ import type { Discovery, Tokens } from "./types";
2
+ export declare function refreshTokens(args: {
3
+ discovery: Discovery;
4
+ clientId: string;
5
+ clientSecret?: string | null;
6
+ refreshToken: string;
7
+ }, fetchImpl?: typeof fetch): Promise<Tokens>;
@@ -0,0 +1,2 @@
1
+ import type { Discovery } from "./types";
2
+ export declare function registerClient(metadata: Record<string, unknown>, discovery: Discovery, fetchImpl?: typeof fetch): Promise<string | null>;
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ export declare const prmSchema: z.ZodObject<{
3
+ resource: z.ZodOptional<z.ZodString>;
4
+ authorization_servers: z.ZodOptional<z.ZodArray<z.ZodString>>;
5
+ scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
6
+ }, z.core.$strip>;
7
+ export declare const metadataSchema: z.ZodObject<{
8
+ issuer: z.ZodString;
9
+ authorization_endpoint: z.ZodString;
10
+ token_endpoint: z.ZodString;
11
+ registration_endpoint: z.ZodOptional<z.ZodString>;
12
+ scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ client_id_metadata_document_supported: z.ZodOptional<z.ZodBoolean>;
14
+ }, z.core.$strip>;
15
+ export declare const tokenSchema: z.ZodObject<{
16
+ access_token: z.ZodString;
17
+ refresh_token: z.ZodOptional<z.ZodString>;
18
+ expires_in: z.ZodOptional<z.ZodNumber>;
19
+ scope: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>;
@@ -0,0 +1,12 @@
1
+ import type { z } from "zod";
2
+ import type { tokenSchema } from "./schema";
3
+ export type Tokens = z.infer<typeof tokenSchema>;
4
+ export type Discovery = {
5
+ resource: string;
6
+ issuer: string;
7
+ authorizationEndpoint: string;
8
+ tokenEndpoint: string;
9
+ registrationEndpoint: string | null;
10
+ scope: string | null;
11
+ clientIdMetadataSupported: boolean;
12
+ };
@@ -0,0 +1,4 @@
1
+ export declare function annotationsFor(method: string): {
2
+ readOnlyHint: boolean;
3
+ destructiveHint: boolean;
4
+ };
@@ -0,0 +1 @@
1
+ export declare function appendParams(params: URLSearchParams, values: unknown): void;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiCall, ToolResult, Upstream } from "../types";
2
+ export declare function callOpenApi(upstream: Upstream, call: OpenApiCall, inputSchema: unknown, args: unknown): Promise<ToolResult>;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiDocument } from "./types";
2
+ export declare function collectDefs(document: OpenApiDocument, used: Set<string>): Record<string, unknown>;
@@ -0,0 +1,6 @@
1
+ export declare const OPERATION_METHODS: Set<string>;
2
+ export declare const READ_ONLY_METHODS: Set<string>;
3
+ export declare const BODYLESS_METHODS: Set<string>;
4
+ export declare const BODY_TYPES: readonly [readonly ["application/json", "json"], readonly ["application/x-www-form-urlencoded", "form"]];
5
+ export declare const IGNORED_HEADERS: Set<string>;
6
+ export declare const RESERVED_HEADERS: RegExp;
@@ -0,0 +1,2 @@
1
+ import type { SpecDefaults } from "../types";
2
+ export declare function discoveredOauth(url: string, fetchImpl: typeof fetch): Promise<SpecDefaults["oauth"] | null>;
@@ -0,0 +1,2 @@
1
+ import { type Document } from "yaml";
2
+ export declare function hasCyclicAlias(document: Document): boolean;
@@ -0,0 +1,2 @@
1
+ export { callOpenApi } from "./call-openapi";
2
+ export { readOpenApi } from "./read-openapi";
@@ -0,0 +1,2 @@
1
+ import type { OpenApiDocument, Parameter, RequestBody } from "./types";
2
+ export declare function inputSchema(document: OpenApiDocument, parameters: Parameter[], body: RequestBody): Record<string, unknown>;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiDocument, Parameter } from "./types";
2
+ export declare function mergedParameters(document: OpenApiDocument, pathLevel: unknown[], operationLevel: unknown[]): Parameter[];
@@ -0,0 +1,3 @@
1
+ import type { UpstreamTool } from "../types";
2
+ import type { OpenApiDocument, OperationSource } from "./types";
3
+ export declare function operationTool(document: OpenApiDocument, source: OperationSource): UpstreamTool | null;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiDocument, OperationSource } from "./types";
2
+ export declare function operationsOf(document: OpenApiDocument): OperationSource[];
@@ -0,0 +1,2 @@
1
+ import type { ParamGroup, ParamPlace, Parameter } from "./types";
2
+ export declare function paramGroup(parameters: Parameter[], place: ParamPlace): ParamGroup | null;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiDocument } from "./types";
2
+ export declare function parseDocument(text: string): OpenApiDocument;
@@ -0,0 +1 @@
1
+ export declare function pathSegment(value: unknown): string;
@@ -0,0 +1,6 @@
1
+ import type { ReadResult } from "../types";
2
+ export declare function readOpenApi(source: {
3
+ spec_url: string;
4
+ } | {
5
+ document: string;
6
+ }, fetchImpl: typeof fetch): Promise<ReadResult>;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiDocument, RequestBody } from "./types";
2
+ export declare function requestBodySchema(document: OpenApiDocument, requestBody: unknown): RequestBody | null;
@@ -0,0 +1,5 @@
1
+ import type { OpenApiCall } from "../types";
2
+ export declare function requestBody(kind: OpenApiCall["body"], value: unknown): {
3
+ text: string;
4
+ type: string;
5
+ } | null;
@@ -0,0 +1,2 @@
1
+ import type { UpstreamAuth } from "../types";
2
+ export declare function requestHeaders(auth: UpstreamAuth, values?: Record<string, unknown>): Headers;
@@ -0,0 +1,2 @@
1
+ import type { OpenApiArgs } from "./types";
2
+ export declare function requestUrl(base: string, template: string, { path, query }: OpenApiArgs): URL;
@@ -0,0 +1 @@
1
+ export declare function resolveRef(document: unknown, node: unknown): unknown;
@@ -0,0 +1 @@
1
+ export declare function rewriteRefs(node: unknown, used: Set<string>): unknown;
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+ export declare const documentSchema: z.ZodObject<{
3
+ paths: z.ZodRecord<z.ZodString, z.ZodUnknown>;
4
+ components: z.ZodOptional<z.ZodObject<{
5
+ schemas: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
6
+ securitySchemes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
7
+ }, z.core.$loose>>;
8
+ }, z.core.$loose>;
9
+ export declare const pathItemObjectSchema: z.ZodObject<{
10
+ parameters: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
11
+ }, z.core.$loose>;
12
+ export declare const operationObjectSchema: z.ZodObject<{
13
+ operationId: z.ZodOptional<z.ZodString>;
14
+ summary: z.ZodOptional<z.ZodString>;
15
+ description: z.ZodOptional<z.ZodString>;
16
+ parameters: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
17
+ requestBody: z.ZodOptional<z.ZodUnknown>;
18
+ }, z.core.$strip>;
19
+ export declare const parameterObjectSchema: z.ZodObject<{
20
+ name: z.ZodString;
21
+ in: z.ZodEnum<{
22
+ cookie: "cookie";
23
+ header: "header";
24
+ path: "path";
25
+ query: "query";
26
+ }>;
27
+ required: z.ZodOptional<z.ZodBoolean>;
28
+ description: z.ZodOptional<z.ZodString>;
29
+ schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
30
+ }, z.core.$strip>;
31
+ export declare const requestBodyObjectSchema: z.ZodObject<{
32
+ required: z.ZodOptional<z.ZodBoolean>;
33
+ content: z.ZodRecord<z.ZodString, z.ZodObject<{
34
+ schema: z.ZodOptional<z.ZodUnknown>;
35
+ }, z.core.$strip>>;
36
+ }, z.core.$strip>;
37
+ export declare const refObjectSchema: z.ZodObject<{
38
+ $ref: z.ZodString;
39
+ }, z.core.$strip>;
40
+ export declare const apiKeySchemeSchema: z.ZodObject<{
41
+ type: z.ZodLiteral<"apiKey">;
42
+ in: z.ZodEnum<{
43
+ header: "header";
44
+ query: "query";
45
+ }>;
46
+ name: z.ZodString;
47
+ }, z.core.$strip>;
48
+ export declare const oauth2SchemeSchema: z.ZodObject<{
49
+ type: z.ZodLiteral<"oauth2">;
50
+ flows: z.ZodObject<{
51
+ authorizationCode: z.ZodObject<{
52
+ authorizationUrl: z.ZodString;
53
+ tokenUrl: z.ZodString;
54
+ scopes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
55
+ }, z.core.$strip>;
56
+ }, z.core.$strip>;
57
+ }, z.core.$strip>;
58
+ export declare const openIdSchemeSchema: z.ZodObject<{
59
+ type: z.ZodLiteral<"openIdConnect">;
60
+ openIdConnectUrl: z.ZodString;
61
+ }, z.core.$strip>;
62
+ export declare const discoverySchema: z.ZodObject<{
63
+ authorization_endpoint: z.ZodString;
64
+ token_endpoint: z.ZodString;
65
+ scopes_supported: z.ZodOptional<z.ZodArray<z.ZodString>>;
66
+ }, z.core.$strip>;
@@ -0,0 +1,3 @@
1
+ import type { SpecDefaults } from "../types";
2
+ import type { OpenApiDocument } from "./types";
3
+ export declare function specDefaults(document: OpenApiDocument, fetchImpl: typeof fetch): Promise<SpecDefaults>;
@@ -0,0 +1 @@
1
+ export declare function toolName(operationId: string | undefined, method: string, path: string): string;
@@ -0,0 +1,27 @@
1
+ import type { z } from "zod";
2
+ import type { OpenApiCall } from "../types";
3
+ import type { documentSchema, parameterObjectSchema } from "./schema";
4
+ export type OpenApiDocument = z.infer<typeof documentSchema>;
5
+ export type Parameter = z.infer<typeof parameterObjectSchema>;
6
+ export type ParamPlace = Exclude<Parameter["in"], "cookie">;
7
+ export type ParamGroup = {
8
+ schema: unknown;
9
+ required: boolean;
10
+ };
11
+ export type RequestBody = {
12
+ kind: OpenApiCall["body"];
13
+ schema: unknown;
14
+ required: boolean;
15
+ };
16
+ export type OperationSource = {
17
+ path: string;
18
+ method: string;
19
+ pathParameters: unknown[];
20
+ operation: unknown;
21
+ };
22
+ export type OpenApiArgs = {
23
+ path?: Record<string, unknown>;
24
+ query?: Record<string, unknown>;
25
+ header?: Record<string, unknown>;
26
+ body?: unknown;
27
+ };
@@ -0,0 +1 @@
1
+ export declare function uniqueNames(names: string[]): string[];
@@ -0,0 +1 @@
1
+ export declare function yamlValue(text: string): unknown;
@@ -0,0 +1,4 @@
1
+ export declare function readCapped(body: ReadableStream<Uint8Array> | null, max: number): Promise<{
2
+ text: string;
3
+ truncated: boolean;
4
+ }>;
@@ -0,0 +1,2 @@
1
+ import type { ReadResult, ReadToolsInput } from "./types";
2
+ export declare function readTools(input: ReadToolsInput): Promise<ReadResult>;
@@ -0,0 +1,2 @@
1
+ import type { UpstreamTool } from "./types";
2
+ export declare function staleToolNames(existing: string[], fresh: Pick<UpstreamTool, "name">[]): string[];
@@ -0,0 +1,5 @@
1
+ import type { ToolResult } from "./types";
2
+ export declare function textResult(text: string, { isError, truncated }: {
3
+ isError: boolean;
4
+ truncated?: boolean;
5
+ }): ToolResult;
@@ -0,0 +1,2 @@
1
+ import type { ToolRow, UpstreamTool } from "./types";
2
+ export declare function toolRowsOf(serverId: string, owner: string | null, tools: UpstreamTool[], now: number): ToolRow[];
@@ -0,0 +1,93 @@
1
+ import type { KINDS } from "./constants";
2
+ import type { McpSession } from "./mcp/types";
3
+ export type McpKind = (typeof KINDS)[number];
4
+ export type UpstreamAuth = {
5
+ type: "none";
6
+ } | {
7
+ type: "bearer";
8
+ token: string;
9
+ } | {
10
+ type: "api_key";
11
+ in: "header" | "query";
12
+ name: string;
13
+ value: string;
14
+ } | {
15
+ type: "basic";
16
+ username: string;
17
+ password: string;
18
+ };
19
+ export type Upstream = {
20
+ url: string;
21
+ auth: UpstreamAuth;
22
+ fetch: typeof fetch;
23
+ timeoutMs?: number;
24
+ };
25
+ export type UpstreamTool = {
26
+ name: string;
27
+ title: string | null;
28
+ description: string;
29
+ input_schema: unknown;
30
+ annotations: unknown;
31
+ call: unknown;
32
+ };
33
+ export type ToolResult = {
34
+ content: [{
35
+ type: "text";
36
+ text: string;
37
+ }];
38
+ isError: boolean;
39
+ };
40
+ export type OpenApiCall = {
41
+ method: string;
42
+ path: string;
43
+ body: "json" | "form" | null;
44
+ };
45
+ export type GraphqlCall = {
46
+ operation: "query" | "mutation";
47
+ field: string;
48
+ arg_types: Record<string, string>;
49
+ selection: string;
50
+ };
51
+ export type SpecDefaults = {
52
+ api_key?: {
53
+ in: "header" | "query";
54
+ name: string;
55
+ };
56
+ oauth?: {
57
+ authorize_url: string;
58
+ token_url: string;
59
+ scopes: string[];
60
+ };
61
+ };
62
+ export type ReadResult = {
63
+ tools: UpstreamTool[];
64
+ dropped: number;
65
+ defaults: SpecDefaults;
66
+ session: McpSession | null;
67
+ complete: boolean;
68
+ };
69
+ export type ToolRow = {
70
+ server_id: string;
71
+ name: string;
72
+ title: string | null;
73
+ description: string;
74
+ input_schema: string;
75
+ annotations: string | null;
76
+ call: string | null;
77
+ owner: string | null;
78
+ updated_at: number;
79
+ };
80
+ export type ReadToolsInput = {
81
+ kind: McpKind;
82
+ upstream: Upstream;
83
+ session: McpSession;
84
+ spec_url: string | null;
85
+ document?: string;
86
+ };
87
+ export type CallToolInput = {
88
+ kind: McpKind;
89
+ upstream: Upstream;
90
+ session: McpSession;
91
+ tool: Pick<ToolRow, "name" | "input_schema" | "call">;
92
+ args: unknown;
93
+ };
package/dist/public.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type { AdminServerItem, CallInput, CompleteOauthInput, ConnectResult, DescribedItem, HubResult, McpServerRow, OwnServerInput, SearchInput, ServerItem, ToolHit, ToolItem, Transient, } from "./rpc/types";
1
+ export type { AdminServerItem, ApiKeySettings, CallInput, CompleteOauthInput, ConnectInput, ConnectResult, CreatedServer, CreateServerInput, DescribedItem, HubResult, McpServerRow, OauthSettings, SearchInput, ServerItem, ToolHit, ToolItem, Transient, } from "./rpc/types";
2
2
  export type { McpHubRpc } from "./rpc/hub-rpc";
3
- export type { McpAuth, McpConnectionStatus } from "./schema";
3
+ export type { McpAuth, McpConnectionStatus, McpKind } from "./schema";
4
4
  export type { McpErrorCode } from "./errors";
@@ -1,4 +1,4 @@
1
- import type { AdminServerInput, AdminServerItem, CallInput, CompleteOauthInput, ConnectResult, DescribedItem, HubResult, McpServerRow, OwnServerInput, SearchInput, ServerItem, ToolHit, ToolItem } from "./types";
1
+ import type { AdminServerInput, AdminServerItem, CallInput, CompleteOauthInput, ConnectInput, ConnectResult, CreatedServer, CreateServerInput, DescribedItem, HubResult, McpServerRow, SearchInput, ServerItem, ToolHit, ToolItem } from "./types";
2
2
  export interface McpHubRpc {
3
3
  search(userId: string, input: SearchInput): Promise<HubResult<ToolHit[]>>;
4
4
  describe(userId: string, tools: string[]): Promise<HubResult<{
@@ -10,15 +10,16 @@ export interface McpHubRpc {
10
10
  serverTools(userId: string, serverId: string): Promise<HubResult<{
11
11
  items: ToolItem[];
12
12
  }>>;
13
- addServer(userId: string, input: OwnServerInput): Promise<McpServerRow>;
14
- connectServer(userId: string, serverId: string, input: {
15
- token?: string;
16
- }): Promise<HubResult<ConnectResult>>;
13
+ createServer(userId: string, input: CreateServerInput): Promise<HubResult<CreatedServer>>;
14
+ connectServer(userId: string, serverId: string, input: ConnectInput): Promise<HubResult<ConnectResult>>;
17
15
  completeOauth(userId: string, input: CompleteOauthInput): Promise<HubResult<{
18
16
  server_id: string;
19
17
  }>>;
20
- refresh(userId: string, serverId: string): Promise<HubResult<{
18
+ refresh(userId: string, serverId: string, input?: {
19
+ document?: string;
20
+ }): Promise<HubResult<{
21
21
  tools: number;
22
+ dropped: number;
22
23
  }>>;
23
24
  removeOwnServer(userId: string, serverId: string): Promise<void>;
24
25
  disconnect(userId: string, serverId: string): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import type { CatalogServer, ToolHit } from "../catalog/types";
2
2
  import type { McpErrorCode } from "../errors";
3
- import type { McpAuth, McpConnectionStatus } from "../schema";
3
+ import type { McpAuth, McpConnectionStatus, McpKind, McpServerRow } from "../schema";
4
4
  export type { AdminServerInput, McpServerRow } from "../schema";
5
5
  export type { ToolHit };
6
6
  export type HubResult<T> = {
@@ -20,6 +20,7 @@ export type Transient = {
20
20
  token_endpoint: string;
21
21
  resource: string;
22
22
  client_id: string;
23
+ client_secret_sealed?: string | null;
23
24
  exp: number;
24
25
  };
25
26
  export type SearchInput = {
@@ -41,13 +42,16 @@ export type DescribedItem = {
41
42
  export type ServerItem = {
42
43
  id: string;
43
44
  name: string;
45
+ kind: McpKind;
44
46
  url: string;
47
+ spec_url: string | null;
45
48
  auth: McpAuth;
46
49
  enabled: boolean;
47
50
  own: boolean;
48
51
  connected: boolean;
49
52
  status: McpConnectionStatus;
50
53
  tool_count: number;
54
+ dropped: number;
51
55
  synced_at: number | null;
52
56
  };
53
57
  export type ToolItem = {
@@ -56,10 +60,51 @@ export type ToolItem = {
56
60
  description: string;
57
61
  annotations: unknown;
58
62
  };
59
- export type OwnServerInput = {
63
+ export type ApiKeySettings = {
64
+ in: "header" | "query";
65
+ name: string;
66
+ };
67
+ export type OauthSettings = {
68
+ authorize_url: string;
69
+ token_url: string;
70
+ scopes?: string[];
71
+ };
72
+ export type CreateServerInput = {
73
+ kind: "mcp";
74
+ name: string;
75
+ url: string;
76
+ auth: McpAuth;
77
+ } | {
78
+ kind: "openapi";
60
79
  name: string;
61
80
  url: string;
81
+ spec_url?: string;
82
+ document?: string;
62
83
  auth: McpAuth;
84
+ api_key?: ApiKeySettings;
85
+ oauth?: OauthSettings;
86
+ } | {
87
+ kind: "graphql";
88
+ name: string;
89
+ url: string;
90
+ document?: string;
91
+ auth: McpAuth;
92
+ api_key?: ApiKeySettings;
93
+ oauth?: OauthSettings;
94
+ token?: string;
95
+ username?: string;
96
+ password?: string;
97
+ };
98
+ export type CreatedServer = McpServerRow & {
99
+ tools: number;
100
+ dropped: number;
101
+ };
102
+ export type ConnectInput = {
103
+ token?: string;
104
+ username?: string;
105
+ password?: string;
106
+ client_id?: string;
107
+ client_secret?: string;
63
108
  };
64
109
  export type ConnectResult = {
65
110
  connected: true;
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- export declare const AUTH_KINDS: readonly ["oauth", "bearer", "none"];
1
+ import type { McpKind, ToolRow } from "./portable/types";
2
+ export { KINDS } from "./portable/constants";
3
+ export type { McpKind };
4
+ export declare const AUTH_KINDS: readonly ["oauth", "bearer", "api_key", "basic", "none"];
2
5
  export type McpAuth = (typeof AUTH_KINDS)[number];
3
6
  export type McpConnectionStatus = "connected" | "expired" | "none";
4
7
  export type McpServerRow = {
@@ -9,17 +12,16 @@ export type McpServerRow = {
9
12
  enabled: number;
10
13
  owner: string | null;
11
14
  updated_at: number;
15
+ kind: McpKind;
16
+ spec_url: string | null;
17
+ auth_in: "header" | "query" | null;
18
+ auth_name: string | null;
19
+ oauth_authorize_url: string | null;
20
+ oauth_token_url: string | null;
21
+ oauth_scopes: string | null;
22
+ dropped: number;
12
23
  };
13
- export type McpToolRow = {
14
- server_id: string;
15
- name: string;
16
- title: string | null;
17
- description: string;
18
- input_schema: string;
19
- annotations: string | null;
20
- owner: string | null;
21
- updated_at: number;
22
- };
24
+ export type McpToolRow = ToolRow;
23
25
  export type AdminServerInput = {
24
26
  id: string;
25
27
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyknown/mcp",
3
- "version": "0.1.4",
3
+ "version": "0.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/anyknown-com/mcp.git"
@@ -32,6 +32,10 @@
32
32
  "build:types": "tsc -p tsconfig.types.json"
33
33
  },
34
34
  "dependencies": {
35
+ "@cfworker/json-schema": "^4.1.1",
36
+ "@scalar/openapi-upgrader": "^0.4.0",
37
+ "graphql": "^17.0.2",
38
+ "yaml": "^2.9.1",
35
39
  "zod": "^4.5.4"
36
40
  },
37
41
  "devDependencies": {