Skip to content

Commit 4b80c88

Browse files
Merge pull request #84 from basementstudio/rewrite-toolextraarguments-type-xmcp-63
Rewrite `ToolExtraArguments` type from scratch
2 parents 5814f70 + 32fe370 commit 4b80c88

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

packages/xmcp/src/types/tool.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,71 @@ export type ToolSchema = Record<
2929
z.ZodType<unknown, z.ZodTypeDef, unknown>
3030
>;
3131

32-
export type ToolExtraArguments = Parameters<ToolCallback<undefined>>[0];
32+
// The ToolExtraArguments type is equivalent to Parameters<ToolCallback<undefined>>[0] from @modelcontextprotocol/sdk but fully resolved to avoid external type dependencies.
33+
/**
34+
* Extra arguments passed to MCP tool functions.
35+
*/
36+
export interface ToolExtraArguments {
37+
/** An abort signal used to communicate if the request was cancelled from the sender's side */
38+
signal: AbortSignal;
39+
40+
/** Information about a validated access token, provided to request handlers */
41+
authInfo?: {
42+
/** The access token */
43+
token: string;
44+
/** The client ID associated with this token */
45+
clientId: string;
46+
/** Scopes associated with this token */
47+
scopes: string[];
48+
/** When the token expires (in seconds since epoch) */
49+
expiresAt?: number;
50+
/** The RFC 8707 resource server identifier for which this token is valid */
51+
resource?: URL;
52+
/** Additional data associated with the token */
53+
extra?: Record<string, unknown>;
54+
};
55+
56+
/** The session ID from the transport, if available */
57+
sessionId?: string;
58+
59+
/** Metadata from the original request */
60+
_meta?: {
61+
/** Progress token for tracking long-running operations */
62+
progressToken?: string | number;
63+
};
64+
65+
/** The JSON-RPC ID of the request being handled */
66+
requestId: string | number;
67+
68+
/** The original HTTP request information */
69+
requestInfo?: {
70+
/** The headers of the request */
71+
headers: Record<string, string | string[] | undefined>;
72+
};
73+
74+
/** Sends a notification that relates to the current request being handled */
75+
sendNotification: (notification: any) => Promise<void>;
76+
77+
/** Sends a request that relates to the current request being handled */
78+
sendRequest: <U extends z.ZodType<object>>(
79+
request: any,
80+
resultSchema: U,
81+
options?: {
82+
/** Progress notification callback */
83+
onprogress?: (progress: any) => void;
84+
/** Abort signal for cancelling the request */
85+
signal?: AbortSignal;
86+
/** Request timeout in milliseconds */
87+
timeout?: number;
88+
/** Whether receiving progress notifications resets the timeout */
89+
resetTimeoutOnProgress?: boolean;
90+
/** Maximum total time to wait for a response */
91+
maxTotalTimeout?: number;
92+
/** Additional transport-specific options */
93+
[key: string]: unknown;
94+
}
95+
) => Promise<z.infer<U>>;
96+
}
3397

3498
export type InferSchema<T extends ToolSchema> = {
3599
[K in keyof T]: z.infer<T[K]>;

0 commit comments

Comments
 (0)