@openagentid/mcp 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/dist/client.js ADDED
@@ -0,0 +1,88 @@
1
+ // src/client.ts
2
+ function withOpenAgentClient(client, config) {
3
+ if (config === null || typeof config !== "object") {
4
+ throw new TypeError("OpenAgentClientConfig must be an object");
5
+ }
6
+ if (config.agent === void 0 || config.agent === null) {
7
+ throw new TypeError("OpenAgentClientConfig.agent is required");
8
+ }
9
+ if (typeof config.agent.signRequest !== "function") {
10
+ throw new TypeError("OpenAgentClientConfig.agent.signRequest is required");
11
+ }
12
+ const interceptor = new ClientInterceptor(config);
13
+ return new Proxy(client, {
14
+ get(target, property, receiver) {
15
+ const value = Reflect.get(target, property, receiver);
16
+ if (typeof value !== "function") {
17
+ return value;
18
+ }
19
+ if (property === "callTool") {
20
+ return interceptor.wrapCallTool(
21
+ value,
22
+ target
23
+ );
24
+ }
25
+ return value.bind(target);
26
+ }
27
+ });
28
+ }
29
+ var ClientInterceptor = class {
30
+ agent;
31
+ audience;
32
+ beforeCall;
33
+ constructor(config) {
34
+ this.agent = config.agent;
35
+ this.audience = config.audience;
36
+ this.beforeCall = config.beforeCall;
37
+ }
38
+ wrapCallTool(original, thisArg) {
39
+ const interceptor = this;
40
+ return async function wrappedCallTool(params, ...rest) {
41
+ const signed = await interceptor.signParams(params);
42
+ let toSend = signed;
43
+ if (interceptor.beforeCall !== void 0) {
44
+ const replacement = await Promise.resolve(
45
+ interceptor.beforeCall(signed)
46
+ );
47
+ if (replacement !== void 0) {
48
+ toSend = {
49
+ ...replacement,
50
+ _meta: replacement._meta ?? signed._meta
51
+ };
52
+ }
53
+ }
54
+ return original.call(thisArg, toSend, ...rest);
55
+ };
56
+ }
57
+ async signParams(params) {
58
+ const identity = await this.agent.signRequest(params.name, this.audience);
59
+ const existingMeta = params._meta ?? {};
60
+ const existingOpenAgent = typeof existingMeta["openagent"] === "object" && existingMeta["openagent"] !== null ? existingMeta["openagent"] : {};
61
+ return {
62
+ ...params,
63
+ _meta: {
64
+ ...existingMeta,
65
+ openagent: {
66
+ ...existingOpenAgent,
67
+ identity
68
+ }
69
+ }
70
+ };
71
+ }
72
+ };
73
+ function buildIdentityMeta(identity) {
74
+ return {
75
+ openagent: {
76
+ identity: {
77
+ did: identity.did,
78
+ proof: identity.proof,
79
+ ...identity.nonce !== void 0 ? { nonce: identity.nonce } : {},
80
+ ...identity.context !== void 0 ? { context: identity.context } : {}
81
+ }
82
+ }
83
+ };
84
+ }
85
+
86
+ export { buildIdentityMeta, withOpenAgentClient };
87
+ //# sourceMappingURL=client.js.map
88
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";AAqEO,SAAS,mBAAA,CACd,QACA,MAAA,EACG;AACH,EAAA,IAAI,MAAA,KAAW,IAAA,IAAQ,OAAO,MAAA,KAAW,QAAA,EAAU;AACjD,IAAA,MAAM,IAAI,UAAU,yCAAyC,CAAA;AAAA,EAC/D;AACA,EAAA,IAAI,MAAA,CAAO,KAAA,KAAU,MAAA,IAAa,MAAA,CAAO,UAAU,IAAA,EAAM;AACvD,IAAA,MAAM,IAAI,UAAU,yCAAyC,CAAA;AAAA,EAC/D;AACA,EAAA,IAAI,OAAO,MAAA,CAAO,KAAA,CAAM,WAAA,KAAgB,UAAA,EAAY;AAClD,IAAA,MAAM,IAAI,UAAU,qDAAqD,CAAA;AAAA,EAC3E;AAEA,EAAA,MAAM,WAAA,GAAc,IAAI,iBAAA,CAAkB,MAAM,CAAA;AAEhD,EAAA,OAAO,IAAI,MAAM,MAAA,EAAQ;AAAA,IACvB,GAAA,CAAI,MAAA,EAAQ,QAAA,EAAU,QAAA,EAAU;AAC9B,MAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,GAAA,CAAI,MAAA,EAAQ,UAAU,QAAQ,CAAA;AACpD,MAAA,IAAI,OAAO,UAAU,UAAA,EAAY;A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AA,EAQtB;AACD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,KAAA,CAAM,YAAY,MAAA,CAAO,IAAA,EAAM,KAAK,QAAQ,CAAA;AACxE,IAAA,MAAM,YAAA,GAAe,MAAA,CAAO,KAAA,IAAS,EAAC;AACtC,IAAA,MAAM,iBAAA,GACJ,OAAO,YAAA,CAAa,WAAW,CAAA,KAAM,QAAA,IACrC,YAAA,CAAa,WAAW,CAAA,KAAM,IAAA,GACzB,YAAA,CAAa,WAAW,IACzB,EAAC;AACP,IAAA,OAAO;AAAA,MACL,GAAG,MAAA;AAAA,MACH,KAAA,EAAO;AAAA,QACL,GAAG,YAAA;AAAA,QACH,SAAA,EAAW;AAAA,UACT,GAAG,iBAAA;AAAA,UACH;AAAA;AACF;AACF,KACF;AAAA,EACF;AACF,CAAA;AAOO,SAAS,kBAAkB,QAAA,EAKN;AAC1B,EAAA,OAAO;AAAA,IACL,SAAA,EAAW;AAAA,MACT,QAAA,EAAU;AAAA,QACR,KAAK,QAAA,CAAS,GAAA;AAAA,QACd,OAAO,QAAA,CAAS,KAAA;AAAA,QAChB,GAAI,SAAS,KAAA,KAAU,MAAA,GAAY,EAAE,KAAA,EAAO,QAAA,CAAS,KAAA,EAAM,GAAI,EAAC;AAAA,QAChE,GAAI,SAAS,OAAA,KAAY,MAAA,GACrB,EAAE,OAAA,EAAS,QAAA,CAAS,OAAA,EAAQ,GAC5B;AAAC;AACP;AACF,GACF;AACF","file":"client.js","sourcesContent":["/**\n * Client-side interceptor for @openagentid/mcp.\n *\n * Adds an OpenAgent identity envelope (`_meta.openagent.identity`) to\n * outbound MCP `tools/call` requests so an authenticated server can\n * verify the caller. The interceptor wraps the MCP client's `callTool`\n * method via a JavaScript Proxy — the rest of the client surface (list\n * tools, list resources, prompts) is forwarded unchanged.\n *\n * Usage:\n *\n * ```ts\n * import { Client } from '@modelcontextprotocol/sdk/client/index.js';\n * import { withOpenAgentClient } from '@openagentid/mcp/client';\n *\n * const client = new Client({ name: 'my-agent', version: '0.1.0' });\n * const authedClient = withOpenAgentClient(client, { agent });\n *\n * await authedClient.callTool({ name: 'search_web', arguments: { q: 'mcp' } });\n * ```\n */\n\nimport { Agent } from './types.js';\n\n/**\n * Minimal MCP client surface used by the interceptor. Like the server\n * adapter, we describe just the methods we need to keep peer-dep\n * compatibility broad.\n */\nexport interface McpClientLike {\n callTool(\n params: {\n name: string;\n arguments?: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n },\n ...rest: unknown[]\n ): Promise<unknown>;\n}\n\nexport interface OpenAgentClientConfig {\n /** The agent doing the calling — used to sign each request. */\n agent: Agent;\n /**\n * Optional audience DID. When set, it is passed to\n * {@link Agent.signRequest} so the proof can be bound to a specific\n * server. Most production deployments should set this.\n */\n audience?: string;\n /**\n * Optional hook fired before every outbound call. Use it for client-\n * side metrics or to mutate the params (e.g., add tracing headers).\n * Returning a value replaces the params.\n */\n beforeCall?: (params: {\n name: string;\n arguments?: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n }) => Promise<\n | { name: string; arguments?: Record<string, unknown>; _meta?: Record<string, unknown> }\n | void\n > | { name: string; arguments?: Record<string, unknown>; _meta?: Record<string, unknown> }\n | void;\n}\n\n/**\n * Wrap an MCP client so every outbound `callTool` carries an OpenAgent\n * identity envelope.\n */\nexport function withOpenAgentClient<T extends McpClientLike>(\n client: T,\n config: OpenAgentClientConfig,\n): T {\n if (config === null || typeof config !== 'object') {\n throw new TypeError('OpenAgentClientConfig must be an object');\n }\n if (config.agent === undefined || config.agent === null) {\n throw new TypeError('OpenAgentClientConfig.agent is required');\n }\n if (typeof config.agent.signRequest !== 'function') {\n throw new TypeError('OpenAgentClientConfig.agent.signRequest is required');\n }\n\n const interceptor = new ClientInterceptor(config);\n\n return new Proxy(client, {\n get(target, property, receiver) {\n const value = Reflect.get(target, property, receiver);\n if (typeof value !== 'function') {\n return value;\n }\n if (property === 'callTool') {\n return interceptor.wrapCallTool(\n value as McpClientLike['callTool'],\n target,\n );\n }\n return value.bind(target);\n },\n }) as T;\n}\n\nclass ClientInterceptor {\n private readonly agent: Agent;\n private readonly audience: string | undefined;\n private readonly beforeCall: OpenAgentClientConfig['beforeCall'];\n\n constructor(config: OpenAgentClientConfig) {\n this.agent = config.agent;\n this.audience = config.audience;\n this.beforeCall = config.beforeCall;\n }\n\n wrapCallTool(\n original: McpClientLike['callTool'],\n thisArg: unknown,\n ): McpClientLike['callTool'] {\n const interceptor = this;\n return async function wrappedCallTool(\n this: unknown,\n params: {\n name: string;\n arguments?: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n },\n ...rest: unknown[]\n ): Promise<unknown> {\n const signed = await interceptor.signParams(params);\n let toSend: {\n name: string;\n arguments?: Record<string, unknown>;\n _meta: Record<string, unknown>;\n } = signed;\n if (interceptor.beforeCall !== undefined) {\n const replacement = await Promise.resolve(\n interceptor.beforeCall(signed),\n );\n if (replacement !== undefined) {\n // Re-attach the signed _meta if the hook stripped it.\n toSend = {\n ...replacement,\n _meta: replacement._meta ?? signed._meta,\n };\n }\n }\n return original.call(thisArg, toSend, ...rest);\n };\n }\n\n private async signParams(params: {\n name: string;\n arguments?: Record<string, unknown>;\n _meta?: Record<string, unknown>;\n }): Promise<{\n name: string;\n arguments?: Record<string, unknown>;\n _meta: Record<string, unknown>;\n }> {\n const identity = await this.agent.signRequest(params.name, this.audience);\n const existingMeta = params._meta ?? {};\n const existingOpenAgent =\n typeof existingMeta['openagent'] === 'object' &&\n existingMeta['openagent'] !== null\n ? (existingMeta['openagent'] as Record<string, unknown>)\n : {};\n return {\n ...params,\n _meta: {\n ...existingMeta,\n openagent: {\n ...existingOpenAgent,\n identity,\n },\n },\n };\n }\n}\n\n/**\n * Helper for tests and tools that want to construct the identity\n * envelope manually without going through a full Agent. Returns a `_meta`\n * object that can be merged into a CallToolRequest's params.\n */\nexport function buildIdentityMeta(identity: {\n did: string;\n proof: string;\n nonce?: string;\n context?: Record<string, unknown>;\n}): Record<string, unknown> {\n return {\n openagent: {\n identity: {\n did: identity.did,\n proof: identity.proof,\n ...(identity.nonce !== undefined ? { nonce: identity.nonce } : {}),\n ...(identity.context !== undefined\n ? { context: identity.context }\n : {}),\n },\n },\n };\n}\n"]}
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ // src/errors.ts
4
+ var McpErrorCode = {
5
+ /** -32600 — request was malformed at the JSON-RPC layer. */
6
+ InvalidRequest: -32600,
7
+ /** -32601 — the requested method/tool was not found. */
8
+ MethodNotFound: -32601,
9
+ /** -32602 — params failed validation. */
10
+ InvalidParams: -32602,
11
+ /** -32603 — internal server error. */
12
+ InternalError: -32603,
13
+ /** -32000 — generic server error (used for auth failures by default). */
14
+ ServerError: -32e3,
15
+ /** -32001 — identity verification failed. */
16
+ AuthenticationFailed: -32001,
17
+ /** -32002 — caller does not hold the required scope. */
18
+ AuthorizationDenied: -32002,
19
+ /** -32003 — skills policy rejected the call. */
20
+ SkillsPolicyDenied: -32003
21
+ };
22
+ var OpenAgentMcpError = class extends Error {
23
+ code;
24
+ data;
25
+ constructor(message, code, data) {
26
+ super(message);
27
+ this.name = "OpenAgentMcpError";
28
+ this.code = code;
29
+ if (data !== void 0) {
30
+ this.data = data;
31
+ }
32
+ }
33
+ /**
34
+ * Convert to a plain JSON-RPC error payload that the MCP SDK can
35
+ * serialize over the wire.
36
+ */
37
+ toJsonRpcError() {
38
+ if (this.data !== void 0) {
39
+ return { code: this.code, message: this.message, data: this.data };
40
+ }
41
+ return { code: this.code, message: this.message };
42
+ }
43
+ };
44
+ var MissingIdentityError = class extends OpenAgentMcpError {
45
+ constructor(toolName) {
46
+ super(
47
+ `Tool '${toolName}' requires an OpenAgent identity in _meta.openagent.identity`,
48
+ McpErrorCode.AuthenticationFailed,
49
+ { toolName }
50
+ );
51
+ this.name = "MissingIdentityError";
52
+ }
53
+ };
54
+ var IdentityVerificationError = class extends OpenAgentMcpError {
55
+ constructor(toolName, cause) {
56
+ super(
57
+ `Identity verification failed for tool '${toolName}': ${formatCause(cause)}`,
58
+ McpErrorCode.AuthenticationFailed,
59
+ { toolName, cause: formatCause(cause) }
60
+ );
61
+ this.name = "IdentityVerificationError";
62
+ }
63
+ };
64
+ var AuthorizationDeniedError = class extends OpenAgentMcpError {
65
+ constructor(toolName, requiredScopes, heldScopes) {
66
+ super(
67
+ `Tool '${toolName}' requires scopes [${requiredScopes.join(", ")}], caller holds [${heldScopes.join(", ")}]`,
68
+ McpErrorCode.AuthorizationDenied,
69
+ {
70
+ toolName,
71
+ requiredScopes: [...requiredScopes],
72
+ heldScopes: [...heldScopes]
73
+ }
74
+ );
75
+ this.name = "AuthorizationDeniedError";
76
+ }
77
+ };
78
+ var SkillsPolicyDeniedError = class extends OpenAgentMcpError {
79
+ constructor(toolName, reason) {
80
+ super(
81
+ `Skills policy denied tool '${toolName}'${reason ? `: ${reason}` : ""}`,
82
+ McpErrorCode.SkillsPolicyDenied,
83
+ reason !== void 0 ? { toolName, reason } : { toolName }
84
+ );
85
+ this.name = "SkillsPolicyDeniedError";
86
+ }
87
+ };
88
+ function formatCause(cause) {
89
+ if (cause instanceof Error) {
90
+ return cause.message;
91
+ }
92
+ if (typeof cause === "string") {
93
+ return cause;
94
+ }
95
+ return "unknown error";
96
+ }
97
+
98
+ exports.AuthorizationDeniedError = AuthorizationDeniedError;
99
+ exports.IdentityVerificationError = IdentityVerificationError;
100
+ exports.McpErrorCode = McpErrorCode;
101
+ exports.MissingIdentityError = MissingIdentityError;
102
+ exports.OpenAgentMcpError = OpenAgentMcpError;
103
+ exports.SkillsPolicyDeniedError = SkillsPolicyDeniedError;
104
+ //# sourceMappingURL=errors.cjs.map
105
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";;;AAUO,IAAM,YAAA,GAAe;AAAA;AAAA,EAE1B,cAAA,EAAgB,MAAA;AAAA;AAAA,EAEhB,cAAA,EAAgB,MAAA;AAAA;AAAA,EAEhB,aAAA,EAAe,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AI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACf;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,eAAA;AACT","file":"errors.cjs","sourcesContent":["/**\n * Error types for @openagentid/mcp.\n *\n * These map onto MCP JSON-RPC error codes so callers see consistent\n * failure modes regardless of which middleware step rejected the call.\n *\n * Reference: https://www.jsonrpc.org/specification#error_object\n */\n\n/** Standard JSON-RPC + MCP error codes used by the middleware. */\nexport const McpErrorCode = {\n /** -32600 — request was malformed at the JSON-RPC layer. */\n InvalidRequest: -32600,\n /** -32601 — the requested method/tool was not found. */\n MethodNotFound: -32601,\n /** -32602 — params failed validation. */\n InvalidParams: -32602,\n /** -32603 — internal server error. */\n InternalError: -32603,\n /** -32000 — generic server error (used for auth failures by default). */\n ServerError: -32000,\n /** -32001 — identity verification failed. */\n AuthenticationFailed: -32001,\n /** -32002 — caller does not hold the required scope. */\n AuthorizationDenied: -32002,\n /** -32003 — skills policy rejected the call. */\n SkillsPolicyDenied: -32003,\n} as const;\n\nexport type McpErrorCodeValue =\n (typeof McpErrorCode)[keyof typeof McpErrorCode];\n\n/**\n * Base class for all middleware errors. Subclasses set a default\n * {@link OpenAgentMcpError.code} that maps to a JSON-RPC error code.\n */\nexport class OpenAgentMcpError extends Error {\n public readonly code: McpErrorCodeValue;\n public readonly data?: Record<string, unknown>;\n\n constructor(\n message: string,\n code: McpErrorCodeValue,\n data?: Record<string, unknown>,\n ) {\n super(message);\n this.name = 'OpenAgentMcpError';\n this.code = code;\n if (data !== undefined) {\n this.data = data;\n }\n }\n\n /**\n * Convert to a plain JSON-RPC error payload that the MCP SDK can\n * serialize over the wire.\n */\n toJsonRpcError(): {\n code: McpErrorCodeValue;\n message: string;\n data?: Record<string, unknown>;\n } {\n if (this.data !== undefined) {\n return { code: this.code, message: this.message, data: this.data };\n }\n return { code: this.code, message: this.message };\n }\n}\n\n/** Caller did not present an OpenAgent identity envelope. */\nexport class MissingIdentityError extends OpenAgentMcpError {\n constructor(toolName: string) {\n super(\n `Tool '${toolName}' requires an OpenAgent identity in _meta.openagent.identity`,\n McpErrorCode.AuthenticationFailed,\n { toolName },\n );\n this.name = 'MissingIdentityError';\n }\n}\n\n/** Identity envelope was present but the verifier rejected it. */\nexport class IdentityVerificationError extends OpenAgentMcpError {\n constructor(toolName: string, cause: unknown) {\n super(\n `Identity verification failed for tool '${toolName}': ${formatCause(cause)}`,\n McpErrorCode.AuthenticationFailed,\n { toolName, cause: formatCause(cause) },\n );\n this.name = 'IdentityVerificationError';\n }\n}\n\n/** Caller's verified identity does not hold the required scopes. */\nexport class AuthorizationDeniedError extends OpenAgentMcpError {\n constructor(\n toolName: string,\n requiredScopes: ReadonlyArray<string>,\n heldScopes: ReadonlyArray<string>,\n ) {\n super(\n `Tool '${toolName}' requires scopes [${requiredScopes.join(', ')}], caller holds [${heldScopes.join(', ')}]`,\n McpErrorCode.AuthorizationDenied,\n {\n toolName,\n requiredScopes: [...requiredScopes],\n heldScopes: [...heldScopes],\n },\n );\n this.name = 'AuthorizationDeniedError';\n }\n}\n\n/** Skills policy hook returned `allow: false`. */\nexport class SkillsPolicyDeniedError extends OpenAgentMcpError {\n constructor(toolName: string, reason: string | undefined) {\n super(\n `Skills policy denied tool '${toolName}'${reason ? `: ${reason}` : ''}`,\n McpErrorCode.SkillsPolicyDenied,\n reason !== undefined ? { toolName, reason } : { toolName },\n );\n this.name = 'SkillsPolicyDeniedError';\n }\n}\n\nfunction formatCause(cause: unknown): string {\n if (cause instanceof Error) {\n return cause.message;\n }\n if (typeof cause === 'string') {\n return cause;\n }\n return 'unknown error';\n}\n"]}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Error types for @openagentid/mcp.
3
+ *
4
+ * These map onto MCP JSON-RPC error codes so callers see consistent
5
+ * failure modes regardless of which middleware step rejected the call.
6
+ *
7
+ * Reference: https://www.jsonrpc.org/specification#error_object
8
+ */
9
+ /** Standard JSON-RPC + MCP error codes used by the middleware. */
10
+ declare const McpErrorCode: {
11
+ /** -32600 — request was malformed at the JSON-RPC layer. */
12
+ readonly InvalidRequest: -32600;
13
+ /** -32601 — the requested method/tool was not found. */
14
+ readonly MethodNotFound: -32601;
15
+ /** -32602 — params failed validation. */
16
+ readonly InvalidParams: -32602;
17
+ /** -32603 — internal server error. */
18
+ readonly InternalError: -32603;
19
+ /** -32000 — generic server error (used for auth failures by default). */
20
+ readonly ServerError: -32000;
21
+ /** -32001 — identity verification failed. */
22
+ readonly AuthenticationFailed: -32001;
23
+ /** -32002 — caller does not hold the required scope. */
24
+ readonly AuthorizationDenied: -32002;
25
+ /** -32003 — skills policy rejected the call. */
26
+ readonly SkillsPolicyDenied: -32003;
27
+ };
28
+ type McpErrorCodeValue = (typeof McpErrorCode)[keyof typeof McpErrorCode];
29
+ /**
30
+ * Base class for all middleware errors. Subclasses set a default
31
+ * {@link OpenAgentMcpError.code} that maps to a JSON-RPC error code.
32
+ */
33
+ declare class OpenAgentMcpError extends Error {
34
+ readonly code: McpErrorCodeValue;
35
+ readonly data?: Record<string, unknown>;
36
+ constructor(message: string, code: McpErrorCodeValue, data?: Record<string, unknown>);
37
+ /**
38
+ * Convert to a plain JSON-RPC error payload that the MCP SDK can
39
+ * serialize over the wire.
40
+ */
41
+ toJsonRpcError(): {
42
+ code: McpErrorCodeValue;
43
+ message: string;
44
+ data?: Record<string, unknown>;
45
+ };
46
+ }
47
+ /** Caller did not present an OpenAgent identity envelope. */
48
+ declare class MissingIdentityError extends OpenAgentMcpError {
49
+ constructor(toolName: string);
50
+ }
51
+ /** Identity envelope was present but the verifier rejected it. */
52
+ declare class IdentityVerificationError extends OpenAgentMcpError {
53
+ constructor(toolName: string, cause: unknown);
54
+ }
55
+ /** Caller's verified identity does not hold the required scopes. */
56
+ declare class AuthorizationDeniedError extends OpenAgentMcpError {
57
+ constructor(toolName: string, requiredScopes: ReadonlyArray<string>, heldScopes: ReadonlyArray<string>);
58
+ }
59
+ /** Skills policy hook returned `allow: false`. */
60
+ declare class SkillsPolicyDeniedError extends OpenAgentMcpError {
61
+ constructor(toolName: string, reason: string | undefined);
62
+ }
63
+
64
+ export { AuthorizationDeniedError, IdentityVerificationError, McpErrorCode, type McpErrorCodeValue, MissingIdentityError, OpenAgentMcpError, SkillsPolicyDeniedError };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Error types for @openagentid/mcp.
3
+ *
4
+ * These map onto MCP JSON-RPC error codes so callers see consistent
5
+ * failure modes regardless of which middleware step rejected the call.
6
+ *
7
+ * Reference: https://www.jsonrpc.org/specification#error_object
8
+ */
9
+ /** Standard JSON-RPC + MCP error codes used by the middleware. */
10
+ declare const McpErrorCode: {
11
+ /** -32600 — request was malformed at the JSON-RPC layer. */
12
+ readonly InvalidRequest: -32600;
13
+ /** -32601 — the requested method/tool was not found. */
14
+ readonly MethodNotFound: -32601;
15
+ /** -32602 — params failed validation. */
16
+ readonly InvalidParams: -32602;
17
+ /** -32603 — internal server error. */
18
+ readonly InternalError: -32603;
19
+ /** -32000 — generic server error (used for auth failures by default). */
20
+ readonly ServerError: -32000;
21
+ /** -32001 — identity verification failed. */
22
+ readonly AuthenticationFailed: -32001;
23
+ /** -32002 — caller does not hold the required scope. */
24
+ readonly AuthorizationDenied: -32002;
25
+ /** -32003 — skills policy rejected the call. */
26
+ readonly SkillsPolicyDenied: -32003;
27
+ };
28
+ type McpErrorCodeValue = (typeof McpErrorCode)[keyof typeof McpErrorCode];
29
+ /**
30
+ * Base class for all middleware errors. Subclasses set a default
31
+ * {@link OpenAgentMcpError.code} that maps to a JSON-RPC error code.
32
+ */
33
+ declare class OpenAgentMcpError extends Error {
34
+ readonly code: McpErrorCodeValue;
35
+ readonly data?: Record<string, unknown>;
36
+ constructor(message: string, code: McpErrorCodeValue, data?: Record<string, unknown>);
37
+ /**
38
+ * Convert to a plain JSON-RPC error payload that the MCP SDK can
39
+ * serialize over the wire.
40
+ */
41
+ toJsonRpcError(): {
42
+ code: McpErrorCodeValue;
43
+ message: string;
44
+ data?: Record<string, unknown>;
45
+ };
46
+ }
47
+ /** Caller did not present an OpenAgent identity envelope. */
48
+ declare class MissingIdentityError extends OpenAgentMcpError {
49
+ constructor(toolName: string);
50
+ }
51
+ /** Identity envelope was present but the verifier rejected it. */
52
+ declare class IdentityVerificationError extends OpenAgentMcpError {
53
+ constructor(toolName: string, cause: unknown);
54
+ }
55
+ /** Caller's verified identity does not hold the required scopes. */
56
+ declare class AuthorizationDeniedError extends OpenAgentMcpError {
57
+ constructor(toolName: string, requiredScopes: ReadonlyArray<string>, heldScopes: ReadonlyArray<string>);
58
+ }
59
+ /** Skills policy hook returned `allow: false`. */
60
+ declare class SkillsPolicyDeniedError extends OpenAgentMcpError {
61
+ constructor(toolName: string, reason: string | undefined);
62
+ }
63
+
64
+ export { AuthorizationDeniedError, IdentityVerificationError, McpErrorCode, type McpErrorCodeValue, MissingIdentityError, OpenAgentMcpError, SkillsPolicyDeniedError };
package/dist/errors.js ADDED
@@ -0,0 +1,98 @@
1
+ // src/errors.ts
2
+ var McpErrorCode = {
3
+ /** -32600 — request was malformed at the JSON-RPC layer. */
4
+ InvalidRequest: -32600,
5
+ /** -32601 — the requested method/tool was not found. */
6
+ MethodNotFound: -32601,
7
+ /** -32602 — params failed validation. */
8
+ InvalidParams: -32602,
9
+ /** -32603 — internal server error. */
10
+ InternalError: -32603,
11
+ /** -32000 — generic server error (used for auth failures by default). */
12
+ ServerError: -32e3,
13
+ /** -32001 — identity verification failed. */
14
+ AuthenticationFailed: -32001,
15
+ /** -32002 — caller does not hold the required scope. */
16
+ AuthorizationDenied: -32002,
17
+ /** -32003 — skills policy rejected the call. */
18
+ SkillsPolicyDenied: -32003
19
+ };
20
+ var OpenAgentMcpError = class extends Error {
21
+ code;
22
+ data;
23
+ constructor(message, code, data) {
24
+ super(message);
25
+ this.name = "OpenAgentMcpError";
26
+ this.code = code;
27
+ if (data !== void 0) {
28
+ this.data = data;
29
+ }
30
+ }
31
+ /**
32
+ * Convert to a plain JSON-RPC error payload that the MCP SDK can
33
+ * serialize over the wire.
34
+ */
35
+ toJsonRpcError() {
36
+ if (this.data !== void 0) {
37
+ return { code: this.code, message: this.message, data: this.data };
38
+ }
39
+ return { code: this.code, message: this.message };
40
+ }
41
+ };
42
+ var MissingIdentityError = class extends OpenAgentMcpError {
43
+ constructor(toolName) {
44
+ super(
45
+ `Tool '${toolName}' requires an OpenAgent identity in _meta.openagent.identity`,
46
+ McpErrorCode.AuthenticationFailed,
47
+ { toolName }
48
+ );
49
+ this.name = "MissingIdentityError";
50
+ }
51
+ };
52
+ var IdentityVerificationError = class extends OpenAgentMcpError {
53
+ constructor(toolName, cause) {
54
+ super(
55
+ `Identity verification failed for tool '${toolName}': ${formatCause(cause)}`,
56
+ McpErrorCode.AuthenticationFailed,
57
+ { toolName, cause: formatCause(cause) }
58
+ );
59
+ this.name = "IdentityVerificationError";
60
+ }
61
+ };
62
+ var AuthorizationDeniedError = class extends OpenAgentMcpError {
63
+ constructor(toolName, requiredScopes, heldScopes) {
64
+ super(
65
+ `Tool '${toolName}' requires scopes [${requiredScopes.join(", ")}], caller holds [${heldScopes.join(", ")}]`,
66
+ McpErrorCode.AuthorizationDenied,
67
+ {
68
+ toolName,
69
+ requiredScopes: [...requiredScopes],
70
+ heldScopes: [...heldScopes]
71
+ }
72
+ );
73
+ this.name = "AuthorizationDeniedError";
74
+ }
75
+ };
76
+ var SkillsPolicyDeniedError = class extends OpenAgentMcpError {
77
+ constructor(toolName, reason) {
78
+ super(
79
+ `Skills policy denied tool '${toolName}'${reason ? `: ${reason}` : ""}`,
80
+ McpErrorCode.SkillsPolicyDenied,
81
+ reason !== void 0 ? { toolName, reason } : { toolName }
82
+ );
83
+ this.name = "SkillsPolicyDeniedError";
84
+ }
85
+ };
86
+ function formatCause(cause) {
87
+ if (cause instanceof Error) {
88
+ return cause.message;
89
+ }
90
+ if (typeof cause === "string") {
91
+ return cause;
92
+ }
93
+ return "unknown error";
94
+ }
95
+
96
+ export { AuthorizationDeniedError, IdentityVerificationError, McpErrorCode, MissingIdentityError, OpenAgentMcpError, SkillsPolicyDeniedError };
97
+ //# sourceMappingURL=errors.js.map
98
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":";AAUO,IAAM,YAAA,GAAe;AAAA;AAAA,EAE1B,cAAA,EAAgB,MAAA;AAAA;AAAA,EAEhB,cAAA,EAAgB,MAAA;AAAA;AAAA,EAEhB,aAAA,EAAe,MAAA;AAAA;AAAA,EAEf,aAAA,EAAe,MAAA;AAAA;AAAA,EAEf,WAAA,EAAa,KAAA;AAAA;AAAA,EAEb,oBAAA,EAAsB,MAAA;AAAA;AAAA,EAEtB,mBAAA,EAAqB,MAAA;AAAA;AAAA,EAErB,kBAAA,EAAoB;AACtB;AASO,IAAM,iBAAA,GAAN,cAAgC,KAAA,CAAM;AAAA,EAC3B,IAAA;AAAA,EACA,IAAA;AAAA,EAEhB,WAAA,CACE,OAAA,EACA,IAAA,EACA,IAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,mBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAI,SAAS,MAAA,EAAW;AACtB,MAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,IACd;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAA,GAIE;AACA,IAAA,IAAI,IAAA,CAAK,SAAS,MAAA,EAAW;AAC3B,MAAA,OAAO,EAAE,MAAM,IAAA,CAAK,IAAA,EAAM,SAAS,IAAA,CAAK,OAAA,EAAS,IAAA,EAAM,IAAA,CAAK,IAAA,EAAK;AAAA,IACnE;AACA,IAAA,OAAO,EAAE,IAAA,EAAM,IAAA,CAAK,IAAA,EAAM,OAAA,EAAS,KAAK,OAAA,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,WAAA,CAAY,UAAkB,MAAA,EAA4B;AACxD,IAAA,KAAA;AAAA,MACE,8BAA8B,QAAQ,CAAA,CAAA,EAAI,SAAS,CAAA,EAAA,EAAK,MAAM,KAAK,EAAE,CAAA,CAAA;AAAA,MACrE,YAAA,CAAa,kBAAA;AAAA,MACb,WAAW,MAAA,GAAY,EAAE,UAAU,MAAA,EAAO,GAAI,EAAE,QAAA;AAAS,KAC3D;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,yBAAA;AAAA,EACd;AACF;AAEA,SAAS,YAAY,KAAA,EAAwB;AAC3C,EAAA,IAAI,iBAAiB,KAAA,EAAO;AAC1B,IAAA,OAAO,KAAA,CAAM,OAAA;AAAA,EACf;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,eAAA;AACT","file":"errors.js","sourcesContent":["/**\n * Error types for @openagentid/mcp.\n *\n * These map onto MCP JSON-RPC error codes so callers see consistent\n * failure modes regardless of which middleware step rejected the call.\n *\n * Reference: https://www.jsonrpc.org/specification#error_object\n */\n\n/** Standard JSON-RPC + MCP error codes used by the middleware. */\nexport const McpErrorCode = {\n /** -32600 — request was malformed at the JSON-RPC layer. */\n InvalidRequest: -32600,\n /** -32601 — the requested method/tool was not found. */\n MethodNotFound: -32601,\n /** -32602 — params failed validation. */\n InvalidParams: -32602,\n /** -32603 — internal server error. */\n InternalError: -32603,\n /** -32000 — generic server error (used for auth failures by default). */\n ServerError: -32000,\n /** -32001 — identity verification failed. */\n AuthenticationFailed: -32001,\n /** -32002 — caller does not hold the required scope. */\n AuthorizationDenied: -32002,\n /** -32003 — skills policy rejected the call. */\n SkillsPolicyDenied: -32003,\n} as const;\n\nexport type McpErrorCodeValue =\n (typeof McpErrorCode)[keyof typeof McpErrorCode];\n\n/**\n * Base class for all middleware errors. Subclasses set a default\n * {@link OpenAgentMcpError.code} that maps to a JSON-RPC error code.\n */\nexport class OpenAgentMcpError extends Error {\n public readonly code: McpErrorCodeValue;\n public readonly data?: Record<string, unknown>;\n\n constructor(\n message: string,\n code: McpErrorCodeValue,\n data?: Record<string, unknown>,\n ) {\n super(message);\n this.name = 'OpenAgentMcpError';\n this.code = code;\n if (data !== undefined) {\n this.data = data;\n }\n }\n\n /**\n * Convert to a plain JSON-RPC error payload that the MCP SDK can\n * serialize over the wire.\n */\n toJsonRpcError(): {\n code: McpErrorCodeValue;\n message: string;\n data?: Record<string, unknown>;\n } {\n if (this.data !== undefined) {\n return { code: this.code, message: this.message, data: this.data };\n }\n return { code: this.code, message: this.message };\n }\n}\n\n/** Caller did not present an OpenAgent identity envelope. */\nexport class MissingIdentityError extends OpenAgentMcpError {\n constructor(toolName: string) {\n super(\n `Tool '${toolName}' requires an OpenAgent identity in _meta.openagent.identity`,\n McpErrorCode.AuthenticationFailed,\n { toolName },\n );\n this.name = 'MissingIdentityError';\n }\n}\n\n/** Identity envelope was present but the verifier rejected it. */\nexport class IdentityVerificationError extends OpenAgentMcpError {\n constructor(toolName: string, cause: unknown) {\n super(\n `Identity verification failed for tool '${toolName}': ${formatCause(cause)}`,\n McpErrorCode.AuthenticationFailed,\n { toolName, cause: formatCause(cause) },\n );\n this.name = 'IdentityVerificationError';\n }\n}\n\n/** Caller's verified identity does not hold the required scopes. */\nexport class AuthorizationDeniedError extends OpenAgentMcpError {\n constructor(\n toolName: string,\n requiredScopes: ReadonlyArray<string>,\n heldScopes: ReadonlyArray<string>,\n ) {\n super(\n `Tool '${toolName}' requires scopes [${requiredScopes.join(', ')}], caller holds [${heldScopes.join(', ')}]`,\n McpErrorCode.AuthorizationDenied,\n {\n toolName,\n requiredScopes: [...requiredScopes],\n heldScopes: [...heldScopes],\n },\n );\n this.name = 'AuthorizationDeniedError';\n }\n}\n\n/** Skills policy hook returned `allow: false`. */\nexport class SkillsPolicyDeniedError extends OpenAgentMcpError {\n constructor(toolName: string, reason: string | undefined) {\n super(\n `Skills policy denied tool '${toolName}'${reason ? `: ${reason}` : ''}`,\n McpErrorCode.SkillsPolicyDenied,\n reason !== undefined ? { toolName, reason } : { toolName },\n );\n this.name = 'SkillsPolicyDeniedError';\n }\n}\n\nfunction formatCause(cause: unknown): string {\n if (cause instanceof Error) {\n return cause.message;\n }\n if (typeof cause === 'string') {\n return cause;\n }\n return 'unknown error';\n}\n"]}