@cogitator-ai/mcp 19.8.2 → 19.9.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/README.md +130 -8
- package/dist/adapter/tool-adapter.d.ts +8 -8
- package/dist/adapter/tool-adapter.d.ts.map +1 -1
- package/dist/adapter/tool-adapter.js +21 -16
- package/dist/adapter/tool-adapter.js.map +1 -1
- package/dist/client/input.d.ts +47 -0
- package/dist/client/input.d.ts.map +1 -0
- package/dist/client/input.js +125 -0
- package/dist/client/input.js.map +1 -0
- package/dist/client/mcp-client.d.ts +84 -8
- package/dist/client/mcp-client.d.ts.map +1 -1
- package/dist/client/mcp-client.js +614 -112
- package/dist/client/mcp-client.js.map +1 -1
- package/dist/client/oauth.d.ts +42 -0
- package/dist/client/oauth.d.ts.map +1 -0
- package/dist/client/oauth.js +171 -0
- package/dist/client/oauth.js.map +1 -0
- package/dist/client/param-headers.d.ts +10 -0
- package/dist/client/param-headers.d.ts.map +1 -0
- package/dist/client/param-headers.js +65 -0
- package/dist/client/param-headers.js.map +1 -0
- package/dist/client/raw-dispatch.d.ts +40 -0
- package/dist/client/raw-dispatch.d.ts.map +1 -0
- package/dist/client/raw-dispatch.js +148 -0
- package/dist/client/raw-dispatch.js.map +1 -0
- package/dist/client/rounds.d.ts +14 -0
- package/dist/client/rounds.d.ts.map +1 -0
- package/dist/client/rounds.js +33 -0
- package/dist/client/rounds.js.map +1 -0
- package/dist/client/tasks.d.ts +70 -0
- package/dist/client/tasks.d.ts.map +1 -0
- package/dist/client/tasks.js +186 -0
- package/dist/client/tasks.js.map +1 -0
- package/dist/client/transports.d.ts +5 -3
- package/dist/client/transports.d.ts.map +1 -1
- package/dist/client/transports.js +9 -8
- package/dist/client/transports.js.map +1 -1
- package/dist/digest.d.ts +8 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +25 -0
- package/dist/digest.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/server/approval.d.ts +17 -5
- package/dist/server/approval.d.ts.map +1 -1
- package/dist/server/approval.js +26 -12
- package/dist/server/approval.js.map +1 -1
- package/dist/server/execution.d.ts +134 -0
- package/dist/server/execution.d.ts.map +1 -0
- package/dist/server/execution.js +185 -0
- package/dist/server/execution.js.map +1 -0
- package/dist/server/mcp-server.d.ts +45 -19
- package/dist/server/mcp-server.d.ts.map +1 -1
- package/dist/server/mcp-server.js +551 -120
- package/dist/server/mcp-server.js.map +1 -1
- package/dist/server/questions.d.ts +19 -2
- package/dist/server/questions.d.ts.map +1 -1
- package/dist/server/questions.js +38 -21
- package/dist/server/questions.js.map +1 -1
- package/dist/server/request-state.d.ts +55 -0
- package/dist/server/request-state.d.ts.map +1 -0
- package/dist/server/request-state.js +66 -0
- package/dist/server/request-state.js.map +1 -0
- package/dist/server/serve-agents.d.ts.map +1 -1
- package/dist/server/serve-agents.js +203 -18
- package/dist/server/serve-agents.js.map +1 -1
- package/dist/server/tasks.d.ts +75 -0
- package/dist/server/tasks.d.ts.map +1 -0
- package/dist/server/tasks.js +280 -0
- package/dist/server/tasks.js.map +1 -0
- package/dist/server/tool-args.d.ts +24 -0
- package/dist/server/tool-args.d.ts.map +1 -0
- package/dist/server/tool-args.js +58 -0
- package/dist/server/tool-args.js.map +1 -0
- package/dist/types.d.ts +341 -11
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -5
package/dist/server/approval.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* can be asked (the client does not support elicitation, or the transport cannot carry it), so
|
|
6
|
-
* the caller decides what an unanswered call means.
|
|
2
|
+
* The elicitation form that asks whether a tool call that needs approval may run: it says why
|
|
3
|
+
* the call asks, and with `allowRemember`, when the call suggests a rule, offers to allow calls
|
|
4
|
+
* like it from now on
|
|
7
5
|
*/
|
|
8
|
-
export
|
|
9
|
-
if (!elicit)
|
|
10
|
-
return undefined;
|
|
6
|
+
export function approvalForm(request, options = {}) {
|
|
11
7
|
const offersAlways = options.allowRemember === true && request.suggestedRule !== undefined;
|
|
12
8
|
const why = request.reason ? ` It asks because: ${request.reason}.` : '';
|
|
13
|
-
|
|
9
|
+
return {
|
|
14
10
|
message: `The agent wants to run ${request.toolName} (${request.description}) with ${JSON.stringify(request.arguments)}.${why} Approve?`,
|
|
15
11
|
schema: {
|
|
16
12
|
type: 'object',
|
|
@@ -27,9 +23,13 @@ export async function elicitApproval(elicit, request, options = {}) {
|
|
|
27
23
|
},
|
|
28
24
|
required: ['approve'],
|
|
29
25
|
},
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The decision an answer to {@link approvalForm} makes. `offersAlways`: whether the form offered
|
|
30
|
+
* to allow calls like it for good
|
|
31
|
+
*/
|
|
32
|
+
export function approvalDecision(reply, offersAlways = false) {
|
|
33
33
|
if (reply.action !== 'accept')
|
|
34
34
|
return { approved: false, reason: 'The user declined' };
|
|
35
35
|
const reason = typeof reply.content.reason === 'string' ? reply.content.reason : undefined;
|
|
@@ -39,4 +39,18 @@ export async function elicitApproval(elicit, request, options = {}) {
|
|
|
39
39
|
? { approved: true, remember: true }
|
|
40
40
|
: { approved: true };
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Ask the person at the MCP client whether a tool call that needs approval may run, through
|
|
44
|
+
* elicitation (see {@link approvalForm}). `undefined` when nobody can be asked (the client does
|
|
45
|
+
* not support elicitation, or the transport cannot carry it), so the caller decides what an
|
|
46
|
+
* unanswered call means.
|
|
47
|
+
*/
|
|
48
|
+
export async function elicitApproval(elicit, request, options = {}) {
|
|
49
|
+
if (!elicit)
|
|
50
|
+
return undefined;
|
|
51
|
+
const reply = await elicit(approvalForm(request, options));
|
|
52
|
+
if (!reply)
|
|
53
|
+
return undefined;
|
|
54
|
+
return approvalDecision(reply, options.allowRemember === true && request.suggestedRule !== undefined);
|
|
55
|
+
}
|
|
42
56
|
//# sourceMappingURL=approval.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/server/approval.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"approval.js","sourceRoot":"","sources":["../../src/server/approval.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA4B,EAC5B,UAAuC,EAAE;IAEzC,MAAM,YAAY,GAAG,OAAO,CAAC,aAAa,KAAK,IAAI,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,CAAC;IAC3F,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,OAAO;QACL,OAAO,EAAE,0BAA0B,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,WAAW,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,GAAG,WAAW;QACxI,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;gBAC9D,GAAG,CAAC,YAAY,IAAI;oBAClB,MAAM,EAAE;wBACN,IAAI,EAAE,SAAS;wBACf,KAAK,EAAE,gDAAgD,OAAO,CAAC,aAAa,GAAG;wBAC/E,OAAO,EAAE,KAAK;qBACf;iBACF,CAAC;gBACF,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;aAC7D;YACD,QAAQ,EAAE,CAAC,SAAS,CAAC;SACtB;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MA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the run waiting for the answer) or by ending its round
|
|
4
|
+
* (`context.input.ask()`, the client calling again with the answers)
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolApprovalRequest } from '@cogitator-ai/types';
|
|
7
|
+
import type { GrantedApproval } from './request-state.js';
|
|
8
|
+
import type { MCPElicitRequest, MCPElicitResult, MCPToolInput } from '../types.js';
|
|
9
|
+
/** A tool result as an MCP server sends it */
|
|
10
|
+
export interface ServerToolResult {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
content: ServerContent[];
|
|
13
|
+
structuredContent?: unknown;
|
|
14
|
+
isError?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type ServerContent = {
|
|
17
|
+
type: 'text';
|
|
18
|
+
text: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: 'image';
|
|
21
|
+
data: string;
|
|
22
|
+
mimeType: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'audio';
|
|
25
|
+
data: string;
|
|
26
|
+
mimeType: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'resource';
|
|
29
|
+
resource: {
|
|
30
|
+
uri: string;
|
|
31
|
+
mimeType?: string;
|
|
32
|
+
text: string;
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
type: 'resource';
|
|
36
|
+
resource: {
|
|
37
|
+
uri: string;
|
|
38
|
+
mimeType?: string;
|
|
39
|
+
blob: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** What a run of a call came to */
|
|
43
|
+
export type ExecutionStep = {
|
|
44
|
+
kind: 'done';
|
|
45
|
+
result: ServerToolResult;
|
|
46
|
+
pendingApproval?: ToolApprovalRequest;
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'ask';
|
|
49
|
+
key: string;
|
|
50
|
+
request: MCPElicitRequest;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'input';
|
|
53
|
+
requests: Record<string, MCPElicitRequest>;
|
|
54
|
+
state: unknown;
|
|
55
|
+
};
|
|
56
|
+
/** What a call carries from round to round */
|
|
57
|
+
export interface ExecutionCarry {
|
|
58
|
+
/** The approvals the person gave the call so far, by the digest of the request */
|
|
59
|
+
approvals: GrantedApproval[];
|
|
60
|
+
/** The arguments the call parsed in its first round, kept for its later rounds */
|
|
61
|
+
args?: unknown;
|
|
62
|
+
/** The answers and kept state the run started with (`context.input`) */
|
|
63
|
+
input?: {
|
|
64
|
+
responses: Record<string, MCPElicitResult>;
|
|
65
|
+
state: unknown;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** What a run of a call gets to ask with */
|
|
69
|
+
export interface ExecutionAskers {
|
|
70
|
+
elicit: (request: MCPElicitRequest) => Promise<MCPElicitResult>;
|
|
71
|
+
/** Asking by ending the round, built from the answers and state the round came with */
|
|
72
|
+
input: (responses: Record<string, MCPElicitResult>, state: unknown, stateRejected: boolean) => MCPToolInput;
|
|
73
|
+
/** The questions of `input.ask()`, once the tool asked them */
|
|
74
|
+
asked: () => {
|
|
75
|
+
requests: Record<string, MCPElicitRequest>;
|
|
76
|
+
state: unknown;
|
|
77
|
+
} | undefined;
|
|
78
|
+
signal: AbortSignal;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A run of a tool call. `next()` resolves with what it came to: its result, a question it
|
|
82
|
+
* waits on (answered with `respond()`), or the questions it ended its round with
|
|
83
|
+
*/
|
|
84
|
+
export declare class CallExecution {
|
|
85
|
+
readonly owner: string;
|
|
86
|
+
readonly tool: string;
|
|
87
|
+
readonly digest: string;
|
|
88
|
+
/** What the call carries from round to round: the approvals given and the last input */
|
|
89
|
+
readonly carry: ExecutionCarry;
|
|
90
|
+
readonly id: `${string}-${string}-${string}-${string}-${string}`;
|
|
91
|
+
readonly controller: AbortController;
|
|
92
|
+
private readonly queue;
|
|
93
|
+
private waiter;
|
|
94
|
+
/** The questions the run waits on, by key, in the order it asked them */
|
|
95
|
+
private readonly waiting;
|
|
96
|
+
private askedCount;
|
|
97
|
+
private expiry;
|
|
98
|
+
private done;
|
|
99
|
+
constructor(owner: string, tool: string, digest: string,
|
|
100
|
+
/** What the call carries from round to round: the approvals given and the last input */
|
|
101
|
+
carry: ExecutionCarry, run: (askers: ExecutionAskers) => Promise<ExecutionStep>);
|
|
102
|
+
/**
|
|
103
|
+
* What the run came to next. Rejects when the run already ended and told what it came to,
|
|
104
|
+
* or when another round already waits on it
|
|
105
|
+
*/
|
|
106
|
+
next(): Promise<ExecutionStep>;
|
|
107
|
+
/** What the run came to next within `ms`, undefined when it is still on its way */
|
|
108
|
+
nextWithin(ms: number): Promise<ExecutionStep | undefined>;
|
|
109
|
+
private refusal;
|
|
110
|
+
/** The first question the run waits on, if it waits on one */
|
|
111
|
+
get question(): {
|
|
112
|
+
key: string;
|
|
113
|
+
request: MCPElicitRequest;
|
|
114
|
+
} | undefined;
|
|
115
|
+
get finished(): boolean;
|
|
116
|
+
/** Answers the question of `key`; false when the run does not wait on it */
|
|
117
|
+
respond(key: string, answer: MCPElicitResult): boolean;
|
|
118
|
+
/** Answers every question the run waits on with `answer`, such as a dismissal */
|
|
119
|
+
respondAll(answer: MCPElicitResult): void;
|
|
120
|
+
/**
|
|
121
|
+
* Keeps the run waiting for the client for `ttlMs`: then its question counts as dismissed
|
|
122
|
+
* and `onExpire` lets go of it
|
|
123
|
+
*/
|
|
124
|
+
park(ttlMs: number, onExpire: () => void): void;
|
|
125
|
+
/** Stops the run: its signal aborts and a question it waits on counts as dismissed */
|
|
126
|
+
cancel(reason?: unknown): void;
|
|
127
|
+
private ask;
|
|
128
|
+
/** The next step in the queue, past questions answered while they waited in it */
|
|
129
|
+
private shift;
|
|
130
|
+
private finish;
|
|
131
|
+
private push;
|
|
132
|
+
private clearExpiry;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/server/execution.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,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,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One run of a tool call on an MCP server, which may stop to ask the person at the client: in
|
|
3
|
+
* place (`context.elicit()`, the run waiting for the answer) or by ending its round
|
|
4
|
+
* (`context.input.ask()`, the client calling again with the answers)
|
|
5
|
+
*/
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
const PENDING = Object.freeze({ status: 'input_required' });
|
|
8
|
+
/**
|
|
9
|
+
* A run of a tool call. `next()` resolves with what it came to: its result, a question it
|
|
10
|
+
* waits on (answered with `respond()`), or the questions it ended its round with
|
|
11
|
+
*/
|
|
12
|
+
export class CallExecution {
|
|
13
|
+
owner;
|
|
14
|
+
tool;
|
|
15
|
+
digest;
|
|
16
|
+
carry;
|
|
17
|
+
id = randomUUID();
|
|
18
|
+
controller = new AbortController();
|
|
19
|
+
queue = [];
|
|
20
|
+
waiter;
|
|
21
|
+
/** The questions the run waits on, by key, in the order it asked them */
|
|
22
|
+
waiting = new Map();
|
|
23
|
+
askedCount = 0;
|
|
24
|
+
expiry;
|
|
25
|
+
done = false;
|
|
26
|
+
constructor(owner, tool, digest,
|
|
27
|
+
/** What the call carries from round to round: the approvals given and the last input */
|
|
28
|
+
carry, run) {
|
|
29
|
+
this.owner = owner;
|
|
30
|
+
this.tool = tool;
|
|
31
|
+
this.digest = digest;
|
|
32
|
+
this.carry = carry;
|
|
33
|
+
let asked;
|
|
34
|
+
const askers = {
|
|
35
|
+
elicit: (request) => this.ask(request),
|
|
36
|
+
input: (responses, state, stateRejected) => ({
|
|
37
|
+
responses,
|
|
38
|
+
state,
|
|
39
|
+
stateRejected,
|
|
40
|
+
ask: (requests, kept) => {
|
|
41
|
+
asked = { requests, state: kept };
|
|
42
|
+
return PENDING;
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
asked: () => asked,
|
|
46
|
+
signal: this.controller.signal,
|
|
47
|
+
};
|
|
48
|
+
run(askers).then((step) => this.finish(step), (error) => this.finish({
|
|
49
|
+
kind: 'done',
|
|
50
|
+
result: {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
isError: true,
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* What the run came to next. Rejects when the run already ended and told what it came to,
|
|
63
|
+
* or when another round already waits on it
|
|
64
|
+
*/
|
|
65
|
+
next() {
|
|
66
|
+
const step = this.shift();
|
|
67
|
+
if (step)
|
|
68
|
+
return Promise.resolve(step);
|
|
69
|
+
const refused = this.refusal();
|
|
70
|
+
if (refused)
|
|
71
|
+
return Promise.reject(refused);
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
this.waiter = resolve;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** What the run came to next within `ms`, undefined when it is still on its way */
|
|
77
|
+
nextWithin(ms) {
|
|
78
|
+
const step = this.shift();
|
|
79
|
+
if (step)
|
|
80
|
+
return Promise.resolve(step);
|
|
81
|
+
const refused = this.refusal();
|
|
82
|
+
if (refused)
|
|
83
|
+
return Promise.reject(refused);
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
const waiter = (next) => {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
resolve(next);
|
|
88
|
+
};
|
|
89
|
+
const timer = setTimeout(() => {
|
|
90
|
+
if (this.waiter === waiter)
|
|
91
|
+
this.waiter = undefined;
|
|
92
|
+
resolve(undefined);
|
|
93
|
+
}, ms);
|
|
94
|
+
this.waiter = waiter;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
refusal() {
|
|
98
|
+
if (this.done)
|
|
99
|
+
return new Error('The run of this call already ended');
|
|
100
|
+
if (this.waiter)
|
|
101
|
+
return new Error('Another round already waits on the run of this call');
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
/** The first question the run waits on, if it waits on one */
|
|
105
|
+
get question() {
|
|
106
|
+
const first = this.waiting.entries().next();
|
|
107
|
+
return first.done ? undefined : { key: first.value[0], request: first.value[1].request };
|
|
108
|
+
}
|
|
109
|
+
get finished() {
|
|
110
|
+
return this.done;
|
|
111
|
+
}
|
|
112
|
+
/** Answers the question of `key`; false when the run does not wait on it */
|
|
113
|
+
respond(key, answer) {
|
|
114
|
+
const waiting = this.waiting.get(key);
|
|
115
|
+
if (!waiting)
|
|
116
|
+
return false;
|
|
117
|
+
this.waiting.delete(key);
|
|
118
|
+
if (this.waiting.size === 0)
|
|
119
|
+
this.clearExpiry();
|
|
120
|
+
waiting.resolve(answer);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/** Answers every question the run waits on with `answer`, such as a dismissal */
|
|
124
|
+
respondAll(answer) {
|
|
125
|
+
for (const key of [...this.waiting.keys()])
|
|
126
|
+
this.respond(key, answer);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Keeps the run waiting for the client for `ttlMs`: then its question counts as dismissed
|
|
130
|
+
* and `onExpire` lets go of it
|
|
131
|
+
*/
|
|
132
|
+
park(ttlMs, onExpire) {
|
|
133
|
+
this.clearExpiry();
|
|
134
|
+
this.expiry = setTimeout(() => {
|
|
135
|
+
this.expiry = undefined;
|
|
136
|
+
this.respondAll({ action: 'cancel' });
|
|
137
|
+
onExpire();
|
|
138
|
+
}, ttlMs);
|
|
139
|
+
this.expiry.unref?.();
|
|
140
|
+
}
|
|
141
|
+
/** Stops the run: its signal aborts and a question it waits on counts as dismissed */
|
|
142
|
+
cancel(reason) {
|
|
143
|
+
this.clearExpiry();
|
|
144
|
+
this.controller.abort(reason);
|
|
145
|
+
this.respondAll({ action: 'cancel' });
|
|
146
|
+
}
|
|
147
|
+
ask(request) {
|
|
148
|
+
if (this.controller.signal.aborted)
|
|
149
|
+
return Promise.resolve({ action: 'cancel' });
|
|
150
|
+
return new Promise((resolve) => {
|
|
151
|
+
const key = `elicit:${++this.askedCount}`;
|
|
152
|
+
this.waiting.set(key, { request, resolve });
|
|
153
|
+
this.push({ kind: 'ask', key, request });
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** The next step in the queue, past questions answered while they waited in it */
|
|
157
|
+
shift() {
|
|
158
|
+
for (;;) {
|
|
159
|
+
const step = this.queue.shift();
|
|
160
|
+
if (step?.kind !== 'ask' || this.waiting.has(step.key))
|
|
161
|
+
return step;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
finish(step) {
|
|
165
|
+
this.done = true;
|
|
166
|
+
this.clearExpiry();
|
|
167
|
+
this.push(step);
|
|
168
|
+
}
|
|
169
|
+
push(step) {
|
|
170
|
+
const waiter = this.waiter;
|
|
171
|
+
if (waiter) {
|
|
172
|
+
this.waiter = undefined;
|
|
173
|
+
waiter(step);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.queue.push(step);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
clearExpiry() {
|
|
180
|
+
if (this.expiry !== undefined)
|
|
181
|
+
clearTimeout(this.expiry);
|
|
182
|
+
this.expiry = undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/server/execution.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAkDzC,MAAM,OAAO,GAAoB,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,gBAAyB,EAAE,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,OAAO,aAAa;IAeb;IACA;IACA;IAEA;IAlBF,EAAE,GAAG,UAAU,EAAE,CAAC;IAClB,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAC3B,KAAK,GAAoB,EAAE,CAAC;IACrC,MAAM,CAA8C;IAC5D,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AC,KAAK,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,IAAI,EAAE,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;QACtE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,IAAmB;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAEO,IAAI,CAAC,IAAmB;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;YACxB,MAAM,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAEO,WAAW;QACjB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exposes Cogitator tools as an MCP server that can be used by
|
|
5
5
|
* other MCP clients (e.g., Claude Desktop, other AI assistants).
|
|
6
|
+
* Serves clients of protocol 2026-07-28 and of 2025-11-25.
|
|
6
7
|
*/
|
|
7
8
|
import type { Tool } from '@cogitator-ai/types';
|
|
8
9
|
import type { MCPServerConfig, MCPResourceConfig, MCPPromptConfig } from '../types.js';
|
|
@@ -28,7 +29,7 @@ import type { MCPServerConfig, MCPResourceConfig, MCPPromptConfig } from '../typ
|
|
|
28
29
|
* ```
|
|
29
30
|
*/
|
|
30
31
|
export declare class MCPServer {
|
|
31
|
-
private
|
|
32
|
+
private stdio?;
|
|
32
33
|
private config;
|
|
33
34
|
private tools;
|
|
34
35
|
private resources;
|
|
@@ -36,6 +37,10 @@ export declare class MCPServer {
|
|
|
36
37
|
private started;
|
|
37
38
|
private ownInvoker?;
|
|
38
39
|
private httpServer?;
|
|
40
|
+
private httpHandler?;
|
|
41
|
+
private readonly stateKey;
|
|
42
|
+
private readonly parked;
|
|
43
|
+
private readonly tasks;
|
|
39
44
|
private readonly sessions;
|
|
40
45
|
constructor(config: MCPServerConfig);
|
|
41
46
|
/**
|
|
@@ -95,7 +100,7 @@ export declare class MCPServer {
|
|
|
95
100
|
* and prompt from the local maps onto it.
|
|
96
101
|
*
|
|
97
102
|
* The maps are the single source of truth: registration with the SDK is
|
|
98
|
-
* deferred until
|
|
103
|
+
* deferred until a connection (stdio) or each incoming request (HTTP), so
|
|
99
104
|
* unregister* calls made before start() are fully honoured and concurrent
|
|
100
105
|
* HTTP requests never share a single server/transport binding.
|
|
101
106
|
*/
|
|
@@ -116,12 +121,28 @@ export declare class MCPServer {
|
|
|
116
121
|
/** The invoker tool calls run through: `config.toolInvoker`, else a Cogitator of its own. */
|
|
117
122
|
private invoker;
|
|
118
123
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
124
|
+
* One round of a tool call. A call that needs the person at the client (an approval,
|
|
125
|
+
* `context.elicit()`, `context.input.ask()`) ends its round with the questions and a signed
|
|
126
|
+
* state, and the client calls again with the answers: on protocol 2026-07-28 the client does,
|
|
127
|
+
* on earlier revisions the MCP SDK asks the client and calls again itself. A call still
|
|
128
|
+
* running after `tasks.promoteAfterMs` becomes a task, for clients that take tasks
|
|
123
129
|
*/
|
|
124
|
-
private
|
|
130
|
+
private handleToolCall;
|
|
131
|
+
/**
|
|
132
|
+
* What the round of `execution` answers: its result, its questions with the state of the call,
|
|
133
|
+
* or the task it became
|
|
134
|
+
*/
|
|
135
|
+
private drive;
|
|
136
|
+
private roundAnswer;
|
|
137
|
+
/** Ends the round with the question `execution` waits on, keeping it waiting for the answer */
|
|
138
|
+
private askInRound;
|
|
139
|
+
/**
|
|
140
|
+
* A run of a tool call through the tool invoker, the way an agent run executes it: schema
|
|
141
|
+
* validation, approval, guardrails, sandbox and `tool.timeout`. In `round` mode an approval the
|
|
142
|
+
* round has no decision for ends the run, to be asked; in `task` mode it is asked in place; in
|
|
143
|
+
* `direct` mode nobody can approve and the call does not run
|
|
144
|
+
*/
|
|
145
|
+
private startExecution;
|
|
125
146
|
/**
|
|
126
147
|
* The result of a tool with an output schema: `structuredContent`, with its JSON as text for
|
|
127
148
|
* clients that read only `content`. It is the result as the schema parses it, so defaults are
|
|
@@ -131,6 +152,15 @@ export declare class MCPServer {
|
|
|
131
152
|
*/
|
|
132
153
|
private structuredResult;
|
|
133
154
|
private toolError;
|
|
155
|
+
/**
|
|
156
|
+
* Ask a client of a revision before 2026-07-28 through MCP elicitation, a request tied to the
|
|
157
|
+
* tool call, for as long as `elicitationTimeoutMs` allows (an answer that does not come in time
|
|
158
|
+
* counts as dismissed). `undefined` when the client cannot answer.
|
|
159
|
+
*/
|
|
160
|
+
private legacyElicit;
|
|
161
|
+
/** The capabilities of the client of this request: its own on 2026-07-28, the handshake's before */
|
|
162
|
+
private clientCapabilities;
|
|
163
|
+
private registerTaskHandlers;
|
|
134
164
|
/**
|
|
135
165
|
* Write a diagnostic line to stderr when logging is enabled.
|
|
136
166
|
*
|
|
@@ -150,28 +180,24 @@ export declare class MCPServer {
|
|
|
150
180
|
* Start the MCP server
|
|
151
181
|
*/
|
|
152
182
|
start(): Promise<void>;
|
|
153
|
-
/** Elicitation needs the client's reply to reach this server: stdio, or HTTP with sessions. */
|
|
154
|
-
private canElicit;
|
|
155
|
-
/**
|
|
156
|
-
* Ask the client's user through MCP elicitation, tied to the tool call so it
|
|
157
|
-
* works on stateless HTTP too, for as long as `elicitationTimeoutMs` allows (an
|
|
158
|
-
* answer that does not come in time counts as dismissed). `undefined` when the
|
|
159
|
-
* client cannot answer.
|
|
160
|
-
*/
|
|
161
|
-
private elicit;
|
|
162
183
|
/** The ms an elicitation waits: `elicitationTimeoutMs`, `0` as the longest timer Node keeps. */
|
|
163
184
|
private elicitationTimeout;
|
|
185
|
+
private promoteAfter;
|
|
164
186
|
/**
|
|
165
187
|
* The caller of an HTTP request per `config.auth`: `undefined` when the
|
|
166
188
|
* server has no `auth`, `null` when the request is refused.
|
|
167
189
|
*/
|
|
168
190
|
private authenticate;
|
|
169
191
|
/**
|
|
170
|
-
* A request in session mode: a request without a session id starts a
|
|
171
|
-
* session (an `initialize`), the others go to their session's transport.
|
|
172
|
-
*
|
|
192
|
+
* A request of a 2025-era client in session mode: a request without a session id starts a
|
|
193
|
+
* session (an `initialize`), the others go to their session's transport. A session belongs to
|
|
194
|
+
* the caller that started it.
|
|
173
195
|
*/
|
|
174
196
|
private handleSessionRequest;
|
|
197
|
+
/** A request of a 2025-era client without sessions: served on its own */
|
|
198
|
+
private handleStatelessLegacyRequest;
|
|
199
|
+
/** The origins browsers may call the server from, undefined for any */
|
|
200
|
+
private allowedOrigins;
|
|
175
201
|
/**
|
|
176
202
|
* Start HTTP server for MCP
|
|
177
203
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../../src/server/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA8BH,OAAO,KAAK,EACV,IAAI,EAIL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAKV,eAAe,EACf,iBAAiB,EAEjB,eAAe,EAIhB,MAAM,UAAU,CAAC;AAmGlB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAAC,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAkB;IA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