@cotal-ai/connector-core 0.84.0 → 0.85.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/agent.d.ts.map +1 -1
- package/dist/agent.js +8 -3
- package/dist/agent.js.map +1 -1
- package/dist/config.d.ts +10 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/docs-bundle.generated.d.ts +1 -1
- package/dist/docs-bundle.generated.js +7 -7
- package/dist/docs-bundle.generated.js.map +1 -1
- package/dist/gateway.d.ts +95 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +201 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tool-specs.d.ts +13 -2
- package/dist/tool-specs.d.ts.map +1 -1
- package/dist/tool-specs.js +27 -11
- package/dist/tool-specs.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docs-bundle.generated.js","sourceRoot":"","sources":["../src/docs-bundle.generated.ts"],"names":[],"mappings":"AAKA,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,MAAM,UAAU,cAAc;IAC5B,OAAO;QACP,SAAS,EAAE,QAAQ;QACnB,eAAe,EAAE,mEAAmE;QACpF,OAAO,EAAE;YACP;gBACE,MAAM,EAAE,eAAe;gBACvB,OAAO,EAAE,eAAe;gBACxB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,+FAA+F;gBAC1G,MAAM,EAAE,81IAA81I;aACv2I;YACD;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,YAAY;gBACrB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,gHAAgH;gBAC3H,MAAM,EAAE,4tYAA4tY;aACruY;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,wMAAwM;gBACnN,MAAM,EAAE,y2nBAAy2nB;aACl3nB;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,kBAAkB;gBAC3B,MAAM,EAAE,mEAAmE;gBAC3E,SAAS,EAAE,wMAAwM;gBACnN,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"docs-bundle.generated.js","sourceRoot":"","sources":["../src/docs-bundle.generated.ts"],"names":[],"mappings":"AAKA,yFAAyF;AACzF,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,MAAM,UAAU,cAAc;IAC5B,OAAO;QACP,SAAS,EAAE,QAAQ;QACnB,eAAe,EAAE,mEAAmE;QACpF,OAAO,EAAE;YACP;gBACE,MAAM,EAAE,eAAe;gBACvB,OAAO,EAAE,eAAe;gBACxB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,+FAA+F;gBAC1G,MAAM,EAAE,81IAA81I;aACv2I;YACD;gBACE,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,YAAY;gBACrB,MAAM,EAAE,0BAA0B;gBAClC,SAAS,EAAE,gHAAgH;gBAC3H,MAAM,EAAE,4tYAA4tY;aACruY;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,wMAAwM;gBACnN,MAAM,EAAE,y2nBAAy2nB;aACl3nB;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,kBAAkB;gBAC3B,MAAM,EAAE,mEAAmE;gBAC3E,SAAS,EAAE,wMAAwM;gBACnN,MAAM,EAAE,60wCAA60wC;aACt1wC;YACD;gBACE,MAAM,EAAE,0BAA0B;gBAClC,OAAO,EAAE,qBAAqB;gBAC9B,MAAM,EAAE,mCAAmC;gBAC3C,SAAS,EAAE,gGAAgG;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gBACnB,OAAO,EAAE,gCAAgC;gBACzC,MAAM,EAAE,qBAAqB;gBAC7B,SAAS,EAAE,iEAAiE;gBAC5E,MAAM,EAAE,uq+EAAuq+E;aAChr+E;YACD;gBACE,MAAM,EAAE,cAAc;gBACtB,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,qBAAqB;gBAC7B,SAAS,EAAE,uHAAuH;gBAClI,MAAM,EAAE,0tsBAA0tsB;aACnusB;YACD;gBACE,MAAM,EAAE,WAAW;gBACnB,OAAO,EAAE,eAAe;gBACxB,MAAM,EAAE,uBAAuB;gBAC/B,SAAS,EAAE,kHAAkH;gBAC7H,MAAM,EAAE,wq8CAAwq8C;aACjr8C;SACF;QACD,MAAM,EAAE;YACN,OAAO,EAAE,0BAA0B;YACnC,MAAM,EAAE,ip7iBAAip7iB;SAC1p7iB;QACD,MAAM,EAAE;YACN,OAAO,EAAE,mCAAmC;YAC5C,MAAM,EAAE,i9mGAAi9mG;SAC19mG;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,oCAAoC;YAC7C,MAAM,EAAE,m4pBAAm4pB;SAC54pB;KACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Cotal tool surface for a REMOTE MCP server: one server, many conversations.
|
|
3
|
+
*
|
|
4
|
+
* A stdio connector is one process per session, so its tools reach the mesh through the one
|
|
5
|
+
* {@link MeshAgent} that process owns. A remote server has no such anchor. A hosted MCP client such
|
|
6
|
+
* as Claude pools one OAuth bearer and one MCP transport session across every conversation of an
|
|
7
|
+
* account, so nothing on a request says which conversation sent it. Each conversation therefore
|
|
8
|
+
* opens its own connection with `cotal_connect` and names it on every later call. A missing or
|
|
9
|
+
* foreign handle refuses and runs nothing. No call falls back to the account's last, only or most
|
|
10
|
+
* recent connection, because that would put one conversation's words under another's identity.
|
|
11
|
+
*
|
|
12
|
+
* The embedder owns everything account-shaped through {@link GatewayHost}: authentication,
|
|
13
|
+
* credential issuance and revocation, and durable records. This module owns the surface, the name
|
|
14
|
+
* rule and, through {@link handleGatewayRequest}, the MCP server itself, so an embedder never needs
|
|
15
|
+
* an MCP SDK of its own.
|
|
16
|
+
*/
|
|
17
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
18
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
19
|
+
import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
20
|
+
import type { MeshAgent } from "./agent.js";
|
|
21
|
+
import type { AgentConfig } from "./config.js";
|
|
22
|
+
/** Thrown by {@link GatewayHost.open} when, and only when, the issuer reports that the name already
|
|
23
|
+
* exists. It is the one failure that moves `cotal_connect` to the next candidate name. An auth,
|
|
24
|
+
* quota, permission or network failure must be any other error, so it reaches the caller instead
|
|
25
|
+
* of being retried under a different name. */
|
|
26
|
+
export declare class NameTaken extends Error {
|
|
27
|
+
readonly taken: string;
|
|
28
|
+
constructor(taken: string);
|
|
29
|
+
}
|
|
30
|
+
/** One live connection: a mesh identity serving one conversation. */
|
|
31
|
+
export interface GatewayConnection {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly agent: MeshAgent;
|
|
34
|
+
readonly config: AgentConfig;
|
|
35
|
+
}
|
|
36
|
+
/** What the embedding service supplies. Every method receives the authenticated account, never a
|
|
37
|
+
* value a tool argument chose. */
|
|
38
|
+
export interface GatewayHost {
|
|
39
|
+
/** The account the request authenticated as. Throw when the request carries no valid
|
|
40
|
+
* authentication; the tool then runs nothing. */
|
|
41
|
+
account(auth: AuthInfo | undefined): string;
|
|
42
|
+
/** Open a fresh connection for `account` named exactly `name`. Throw {@link NameTaken} only for
|
|
43
|
+
* an authoritative name collision. The collision check and the issue must be one atomic step per
|
|
44
|
+
* account: an `open` racing another for the same name throws `NameTaken` rather than also
|
|
45
|
+
* succeeding, or two conversations end up sharing one name. Error messages reach the caller,
|
|
46
|
+
* so they must not carry secrets. */
|
|
47
|
+
open(account: string, name: string): Promise<GatewayConnection>;
|
|
48
|
+
/** The connection `id` if `account` owns it, otherwise undefined. Never a default. */
|
|
49
|
+
find(account: string, id: string): Promise<GatewayConnection | undefined>;
|
|
50
|
+
/** Stop and release one connection `account` owns. False when it owns no such connection. */
|
|
51
|
+
close(account: string, id: string): Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/** The mesh tools a remote conversation may call. Process and seat authority (spawn, despawn,
|
|
54
|
+
* persona, run, yield, reconnect) belongs to a supervised local seat and is not offered here. */
|
|
55
|
+
export declare const GATEWAY_TOOLS: ReadonlySet<string>;
|
|
56
|
+
/** How many names `cotal_connect` tries: the requested one, then `_2` up to this suffix. */
|
|
57
|
+
export declare const GATEWAY_NAME_ATTEMPTS = 20;
|
|
58
|
+
/** The names `cotal_connect` tries for `base`, in order. */
|
|
59
|
+
export declare function gatewayNames(base: string, attempts?: number): string[];
|
|
60
|
+
/**
|
|
61
|
+
* Register the remote surface on `server`: `cotal_connect`, `cotal_disconnect`, and each tool in
|
|
62
|
+
* {@link GATEWAY_TOOLS} with a required `connection_id`.
|
|
63
|
+
*
|
|
64
|
+
* Each call is parsed and run against the spec built from that connection's own configuration, so a
|
|
65
|
+
* connection's channels and grants decide what the call does.
|
|
66
|
+
*/
|
|
67
|
+
export declare function registerCotalGatewayTools(server: McpServer, host: GatewayHost, source?: string): void;
|
|
68
|
+
/** The server instructions {@link handleGatewayRequest} sends when the embedder gives none. */
|
|
69
|
+
export declare const GATEWAY_INSTRUCTIONS: string;
|
|
70
|
+
/** One HTTP request to a gateway endpoint. */
|
|
71
|
+
export interface GatewayRequest {
|
|
72
|
+
req: IncomingMessage;
|
|
73
|
+
res: ServerResponse;
|
|
74
|
+
/** The parsed JSON body, for a framework that already read the request stream. Omit it and the
|
|
75
|
+
* body is read from `req`. */
|
|
76
|
+
body?: unknown;
|
|
77
|
+
/** What the embedder authenticated this request as, handed to {@link GatewayHost.account}.
|
|
78
|
+
* Without it every tool refuses and runs nothing. */
|
|
79
|
+
auth?: AuthInfo;
|
|
80
|
+
/** The source tag on messages this endpoint sends. */
|
|
81
|
+
source?: string;
|
|
82
|
+
instructions?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Serve one HTTP request to a gateway endpoint with this package's own MCP server and Streamable
|
|
86
|
+
* HTTP transport. The embedder authenticates and routes. It never builds an MCP server, so its own
|
|
87
|
+
* SDK or zod version cannot disagree with the one these tools were written against.
|
|
88
|
+
*
|
|
89
|
+
* The endpoint is stateless. Each POST gets a fresh server and transport and a JSON response, so
|
|
90
|
+
* nothing survives between requests except what the host stores. There is no server-initiated
|
|
91
|
+
* stream and no session to end, so every other method answers 405, as the Streamable HTTP
|
|
92
|
+
* transport allows.
|
|
93
|
+
*/
|
|
94
|
+
export declare function handleGatewayRequest(host: GatewayHost, r: GatewayRequest): Promise<void>;
|
|
95
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gDAAgD,CAAC;AAI/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;;+CAG+C;AAC/C,qBAAa,SAAU,SAAQ,KAAK;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CAInC;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAA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;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB9F"}
|
package/dist/gateway.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { assertValidName } from "@cotal-ai/core";
|
|
5
|
+
import { cotalToolSpecs, parseToolArgs } from "./tool-specs.js";
|
|
6
|
+
/** Thrown by {@link GatewayHost.open} when, and only when, the issuer reports that the name already
|
|
7
|
+
* exists. It is the one failure that moves `cotal_connect` to the next candidate name. An auth,
|
|
8
|
+
* quota, permission or network failure must be any other error, so it reaches the caller instead
|
|
9
|
+
* of being retried under a different name. */
|
|
10
|
+
export class NameTaken extends Error {
|
|
11
|
+
taken;
|
|
12
|
+
constructor(taken) {
|
|
13
|
+
super(`name ${JSON.stringify(taken)} is taken`);
|
|
14
|
+
this.taken = taken;
|
|
15
|
+
this.name = "NameTaken";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** The mesh tools a remote conversation may call. Process and seat authority (spawn, despawn,
|
|
19
|
+
* persona, run, yield, reconnect) belongs to a supervised local seat and is not offered here. */
|
|
20
|
+
export const GATEWAY_TOOLS = new Set([
|
|
21
|
+
"cotal_orientation",
|
|
22
|
+
"cotal_connection_status",
|
|
23
|
+
"cotal_roster",
|
|
24
|
+
"cotal_inbox",
|
|
25
|
+
"cotal_send",
|
|
26
|
+
"cotal_dm",
|
|
27
|
+
"cotal_anycast",
|
|
28
|
+
"cotal_status",
|
|
29
|
+
"cotal_channel_info",
|
|
30
|
+
"cotal_channels",
|
|
31
|
+
"cotal_channel_mode",
|
|
32
|
+
"cotal_join",
|
|
33
|
+
"cotal_leave",
|
|
34
|
+
]);
|
|
35
|
+
/** How many names `cotal_connect` tries: the requested one, then `_2` up to this suffix. */
|
|
36
|
+
export const GATEWAY_NAME_ATTEMPTS = 20;
|
|
37
|
+
/** The names `cotal_connect` tries for `base`, in order. */
|
|
38
|
+
export function gatewayNames(base, attempts = GATEWAY_NAME_ATTEMPTS) {
|
|
39
|
+
return [base, ...Array.from({ length: attempts - 1 }, (_, i) => `${base}_${i + 2}`)];
|
|
40
|
+
}
|
|
41
|
+
const CONNECTION_REQUIRED = "CONNECTION_REQUIRED: no connection with that connection_id belongs to this account. Call cotal_connect " +
|
|
42
|
+
"for this conversation and pass the connection_id it returns. Nothing was done.";
|
|
43
|
+
/** One tool list serves every connection, so the advertised shapes come from a configuration with
|
|
44
|
+
* no identity and no channels. Each call still runs against its connection's own configuration. */
|
|
45
|
+
const ADVERTISED = {
|
|
46
|
+
space: "",
|
|
47
|
+
name: "",
|
|
48
|
+
servers: "",
|
|
49
|
+
subscribe: [],
|
|
50
|
+
allowSubscribe: [],
|
|
51
|
+
allowPublish: [],
|
|
52
|
+
kind: "agent",
|
|
53
|
+
tls: false,
|
|
54
|
+
};
|
|
55
|
+
/** `cotal_send`'s channel description is the one advertised text that names a configuration's
|
|
56
|
+
* default channel. Connections can read different channels, so the advertised text names none. */
|
|
57
|
+
const SEND_CHANNEL = "Channel to send on. Omit it to use this connection's default, the first concrete channel it reads and " +
|
|
58
|
+
"may post to (cotal_orientation lists both); with none, an omitted channel is refused. Concrete only, not " +
|
|
59
|
+
"a wildcard like team.>; reply on the channel you received a message on.";
|
|
60
|
+
const CONNECTION_ID = z
|
|
61
|
+
.string()
|
|
62
|
+
.min(1)
|
|
63
|
+
.describe("The connection_id cotal_connect returned in THIS conversation. Never reuse another conversation's.");
|
|
64
|
+
function toContent(r) {
|
|
65
|
+
const content = [{ type: "text", text: r.text }];
|
|
66
|
+
return r.isError ? { content, isError: true } : { content };
|
|
67
|
+
}
|
|
68
|
+
const refuse = (text) => toContent({ text, isError: true });
|
|
69
|
+
function errorText(e) {
|
|
70
|
+
return e instanceof Error ? e.message : String(e);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Register the remote surface on `server`: `cotal_connect`, `cotal_disconnect`, and each tool in
|
|
74
|
+
* {@link GATEWAY_TOOLS} with a required `connection_id`.
|
|
75
|
+
*
|
|
76
|
+
* Each call is parsed and run against the spec built from that connection's own configuration, so a
|
|
77
|
+
* connection's channels and grants decide what the call does.
|
|
78
|
+
*/
|
|
79
|
+
export function registerCotalGatewayTools(server, host, source = "gateway") {
|
|
80
|
+
server.registerTool("cotal_connect", {
|
|
81
|
+
title: "Cotal: connect this conversation",
|
|
82
|
+
description: "Join the Cotal mesh as a new agent for THIS conversation and return its connection_id. Call it once per " +
|
|
83
|
+
"conversation, keep the connection_id, and pass it on every other cotal_* call. If the name is taken, the " +
|
|
84
|
+
"next free name is chosen (name_2, name_3, ...) and reported. Never reuse a connection_id from another " +
|
|
85
|
+
"conversation, and call this again if you no longer have this conversation's connection_id.",
|
|
86
|
+
inputSchema: z.strictObject({
|
|
87
|
+
name: z.string().min(1).describe("The agent name to request, for example claude_web."),
|
|
88
|
+
}),
|
|
89
|
+
}, async ({ name }, extra) => {
|
|
90
|
+
let account;
|
|
91
|
+
try {
|
|
92
|
+
account = host.account(extra.authInfo);
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
return refuse(`not authenticated: ${errorText(e)}`);
|
|
96
|
+
}
|
|
97
|
+
for (const candidate of gatewayNames(name)) {
|
|
98
|
+
// A name the mesh would refuse is the caller's to fix, not a collision to rename around.
|
|
99
|
+
try {
|
|
100
|
+
assertValidName(candidate);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
return refuse(`cotal_connect: ${errorText(e)}`);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const c = await host.open(account, candidate);
|
|
107
|
+
const renamed = candidate === name ? "" : ` (${JSON.stringify(name)} was taken)`;
|
|
108
|
+
return toContent({
|
|
109
|
+
text: `Connected as ${c.config.name}${renamed}.\nconnection_id: ${c.id}\nPass this connection_id on every cotal_* call in this conversation.`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
if (e instanceof NameTaken)
|
|
114
|
+
continue;
|
|
115
|
+
return refuse(`cotal_connect failed for ${JSON.stringify(candidate)}: ${errorText(e)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return refuse(`cotal_connect: ${JSON.stringify(name)} and its next ${GATEWAY_NAME_ATTEMPTS - 1} variants are all taken. Choose another name.`);
|
|
119
|
+
});
|
|
120
|
+
server.registerTool("cotal_disconnect", {
|
|
121
|
+
title: "Cotal: disconnect this conversation",
|
|
122
|
+
description: "Leave the mesh for this conversation's connection. Other conversations stay connected.",
|
|
123
|
+
inputSchema: z.strictObject({ connection_id: CONNECTION_ID }),
|
|
124
|
+
}, async ({ connection_id }, extra) => {
|
|
125
|
+
let account;
|
|
126
|
+
try {
|
|
127
|
+
account = host.account(extra.authInfo);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
return refuse(`not authenticated: ${errorText(e)}`);
|
|
131
|
+
}
|
|
132
|
+
return (await host.close(account, connection_id))
|
|
133
|
+
? toContent({ text: `Disconnected ${connection_id}.` })
|
|
134
|
+
: refuse(CONNECTION_REQUIRED);
|
|
135
|
+
});
|
|
136
|
+
for (const spec of cotalToolSpecs(ADVERTISED, source, undefined, GATEWAY_TOOLS)) {
|
|
137
|
+
const channel = spec.name === "cotal_send" ? spec.schema.shape.channel : undefined;
|
|
138
|
+
const shape = channel ? spec.schema.extend({ channel: channel.describe(SEND_CHANNEL) }) : spec.schema;
|
|
139
|
+
server.registerTool(spec.name, {
|
|
140
|
+
title: spec.title,
|
|
141
|
+
description: `${spec.description} Requires this conversation's connection_id from cotal_connect.`,
|
|
142
|
+
inputSchema: shape.extend({ connection_id: CONNECTION_ID }),
|
|
143
|
+
}, async (args, extra) => {
|
|
144
|
+
const { connection_id, ...rest } = args;
|
|
145
|
+
let account;
|
|
146
|
+
try {
|
|
147
|
+
account = host.account(extra.authInfo);
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
return refuse(`not authenticated: ${errorText(e)}`);
|
|
151
|
+
}
|
|
152
|
+
const c = await host.find(account, connection_id);
|
|
153
|
+
if (!c)
|
|
154
|
+
return refuse(CONNECTION_REQUIRED);
|
|
155
|
+
const own = cotalToolSpecs(c.config, source, undefined, GATEWAY_TOOLS).find((s) => s.name === spec.name);
|
|
156
|
+
// Unreachable while GATEWAY_TOOLS holds no capability-gated tool; a future one refuses here.
|
|
157
|
+
if (!own)
|
|
158
|
+
return refuse(`${spec.name} is not available on this connection.`);
|
|
159
|
+
try {
|
|
160
|
+
return toContent(await own.run(c.agent, c.config, parseToolArgs(own, rest)));
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
return refuse(errorText(e));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** The server instructions {@link handleGatewayRequest} sends when the embedder gives none. */
|
|
169
|
+
export const GATEWAY_INSTRUCTIONS = "Cotal connects this conversation to the person's Cotal space. Call cotal_connect once with a short name " +
|
|
170
|
+
"for this conversation, then pass the returned connection_id on every other cotal tool call. Each " +
|
|
171
|
+
"conversation needs its own connection. Never reuse another conversation's connection_id.";
|
|
172
|
+
/**
|
|
173
|
+
* Serve one HTTP request to a gateway endpoint with this package's own MCP server and Streamable
|
|
174
|
+
* HTTP transport. The embedder authenticates and routes. It never builds an MCP server, so its own
|
|
175
|
+
* SDK or zod version cannot disagree with the one these tools were written against.
|
|
176
|
+
*
|
|
177
|
+
* The endpoint is stateless. Each POST gets a fresh server and transport and a JSON response, so
|
|
178
|
+
* nothing survives between requests except what the host stores. There is no server-initiated
|
|
179
|
+
* stream and no session to end, so every other method answers 405, as the Streamable HTTP
|
|
180
|
+
* transport allows.
|
|
181
|
+
*/
|
|
182
|
+
export async function handleGatewayRequest(host, r) {
|
|
183
|
+
if (r.req.method !== "POST") {
|
|
184
|
+
r.res
|
|
185
|
+
.writeHead(405, { allow: "POST", "content-type": "application/json" })
|
|
186
|
+
.end(JSON.stringify({ jsonrpc: "2.0", error: { code: -32000, message: "Method not allowed." }, id: null }));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const server = new McpServer({ name: "cotal", version: "0.0.0" }, { instructions: r.instructions ?? GATEWAY_INSTRUCTIONS });
|
|
190
|
+
registerCotalGatewayTools(server, host, r.source);
|
|
191
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
|
|
192
|
+
r.res.on("close", () => {
|
|
193
|
+
void transport.close();
|
|
194
|
+
void server.close();
|
|
195
|
+
});
|
|
196
|
+
// The transport hands `req.auth` to each tool as `extra.authInfo`.
|
|
197
|
+
r.req.auth = r.auth;
|
|
198
|
+
await server.connect(transport);
|
|
199
|
+
await transport.handleRequest(r.req, r.res, r.body);
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAEnG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,iBAAiB,CAAC;AAIjF;;;+CAG+C;AAC/C,MAAM,OAAO,SAAU,SAAQ,KAAK;IACb;IAArB,YAAqB,KAAa;QAChC,KAAK,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAD7B,UAAK,GAAL,KAAK,CAAQ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/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./tool-specs.js";
|
|
|
16
16
|
export * from "./orientation.js";
|
|
17
17
|
export * from "./docs.js";
|
|
18
18
|
export * from "./tools.js";
|
|
19
|
+
export * from "./gateway.js";
|
|
19
20
|
export * from "./control.js";
|
|
20
21
|
export * from "./relay.js";
|
|
21
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./tool-specs.js";
|
|
|
16
16
|
export * from "./orientation.js";
|
|
17
17
|
export * from "./docs.js";
|
|
18
18
|
export * from "./tools.js";
|
|
19
|
+
export * from "./gateway.js";
|
|
19
20
|
export * from "./control.js";
|
|
20
21
|
export * from "./relay.js";
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/D,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/dist/tool-specs.d.ts
CHANGED
|
@@ -117,8 +117,19 @@ export declare function renderInbox(opts: {
|
|
|
117
117
|
}): InboxResponse;
|
|
118
118
|
/** Routing context for a `<channel …>` tag. Keys must be [A-Za-z0-9_] (others are dropped). */
|
|
119
119
|
export declare function channelMeta(i: InboxItem): Record<string, string>;
|
|
120
|
+
/**
|
|
121
|
+
* The channel a send with none goes to, from the channels the agent reads. A mesh that enforces
|
|
122
|
+
* ACLs refuses a post outside `allowPublish`, so there the default is the first concrete channel
|
|
123
|
+
* the agent reads AND may post to: a read-only channel such as an announcements feed is never it.
|
|
124
|
+
* An open mesh enforces no post ACL, so there it is the first concrete channel read, as the
|
|
125
|
+
* endpoint resolves it. A wildcard subscription like `team.>` is not a destination. Undefined when
|
|
126
|
+
* no channel qualifies; a send without a channel is then refused.
|
|
127
|
+
*/
|
|
128
|
+
export declare function defaultSendChannel(config: Pick<AgentConfig, "allowPublish" | "creds" | "userAuth">, reading: readonly string[]): string | undefined;
|
|
120
129
|
/** The full Cotal tool set for a given config. Renderers iterate this; `source` names the
|
|
121
130
|
* hosting connector and is stamped onto outgoing feedback. An explicit env restricts feedback's
|
|
122
|
-
* Git lookup to its global config; omitted preserves process inheritance and repository lookup.
|
|
123
|
-
|
|
131
|
+
* Git lookup to its global config; omitted preserves process inheritance and repository lookup.
|
|
132
|
+
* `offered` limits the set to those names for a host that serves only part of the surface, and the
|
|
133
|
+
* orientation card then lists only those. */
|
|
134
|
+
export declare function cotalToolSpecs(config: AgentConfig, source?: string, env?: NodeJS.ProcessEnv, offered?: ReadonlySet<string>): CotalToolSpec[];
|
|
124
135
|
//# sourceMappingURL=tool-specs.d.ts.map
|
package/dist/tool-specs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-specs.d.ts","sourceRoot":"","sources":["../src/tool-specs.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAI7E,OAAO,EAA+C,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5F;yDACyD;AACzD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAwED;;;;;;;sGAOsG;AACtG,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;AAExD,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB;;;;8FAI0F;IAC1F,MAAM,EAAE,cAAc,CAAC;IACvB,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE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"true"; // we were addressed by name → high priority
|
|
510
510
|
return m;
|
|
511
511
|
}
|
|
512
|
+
/**
|
|
513
|
+
* The channel a send with none goes to, from the channels the agent reads. A mesh that enforces
|
|
514
|
+
* ACLs refuses a post outside `allowPublish`, so there the default is the first concrete channel
|
|
515
|
+
* the agent reads AND may post to: a read-only channel such as an announcements feed is never it.
|
|
516
|
+
* An open mesh enforces no post ACL, so there it is the first concrete channel read, as the
|
|
517
|
+
* endpoint resolves it. A wildcard subscription like `team.>` is not a destination. Undefined when
|
|
518
|
+
* no channel qualifies; a send without a channel is then refused.
|
|
519
|
+
*/
|
|
520
|
+
export function defaultSendChannel(config, reading) {
|
|
521
|
+
const concrete = reading.filter(isConcreteChannel);
|
|
522
|
+
return isAuthed(config) ? concrete.find((c) => channelInAllow(config.allowPublish, c)) : concrete[0];
|
|
523
|
+
}
|
|
524
|
+
const NO_POSTABLE_DEFAULT = "you may post to none of the channels you read, so there is no default and an omitted channel is refused - name one your post ACL allows (cotal_orientation lists them)";
|
|
512
525
|
/** The full Cotal tool set for a given config. Renderers iterate this; `source` names the
|
|
513
526
|
* hosting connector and is stamped onto outgoing feedback. An explicit env restricts feedback's
|
|
514
|
-
* Git lookup to its global config; omitted preserves process inheritance and repository lookup.
|
|
515
|
-
|
|
527
|
+
* Git lookup to its global config; omitted preserves process inheritance and repository lookup.
|
|
528
|
+
* `offered` limits the set to those names for a host that serves only part of the surface, and the
|
|
529
|
+
* orientation card then lists only those. */
|
|
530
|
+
export function cotalToolSpecs(config, source = "connector", env, offered) {
|
|
516
531
|
// Manager-op tools (cotal_spawn / cotal_persona / cotal_personas) ride the `spawn` capability — publish to the
|
|
517
532
|
// privileged control subject. The AUTH layer is the real boundary: on an authed mesh an agent
|
|
518
533
|
// without the capability is denied at the wire (nats-server); open mode mints no identity, so
|
|
@@ -528,10 +543,7 @@ export function cotalToolSpecs(config, source = "connector", env) {
|
|
|
528
543
|
// The same rule for the workflow-run door (SPEC 14.3): the `run` capability mints the manager's
|
|
529
544
|
// run-* rows, so cotal_run is advertised only where the wire would admit it.
|
|
530
545
|
const canRun = !isAuthed(config) || (config.capabilities?.includes("run") ?? false);
|
|
531
|
-
|
|
532
|
-
// the read set (a wildcard subscription like `team.>` is not a destination). Undefined when the
|
|
533
|
-
// agent is on no channel, in which case there IS no default and a send without one is refused.
|
|
534
|
-
const defaultChannel = config.subscribe.find(isConcreteChannel);
|
|
546
|
+
const defaultChannel = defaultSendChannel(config, config.subscribe);
|
|
535
547
|
const specs = [
|
|
536
548
|
{
|
|
537
549
|
name: "cotal_orientation",
|
|
@@ -543,7 +555,7 @@ export function cotalToolSpecs(config, source = "connector", env) {
|
|
|
543
555
|
run(agent) {
|
|
544
556
|
// Reflect the SAME gated tool list the connector exposes (cotalToolSpecs already filters
|
|
545
557
|
// spawn/persona by capability), so the card can't claim a tool the agent can't call.
|
|
546
|
-
const visible = cotalToolSpecs(config, source).map((s) => ({
|
|
558
|
+
const visible = cotalToolSpecs(config, source, env, offered).map((s) => ({
|
|
547
559
|
name: s.name,
|
|
548
560
|
title: s.title,
|
|
549
561
|
}));
|
|
@@ -912,17 +924,20 @@ export function cotalToolSpecs(config, source = "connector", env) {
|
|
|
912
924
|
channel: z
|
|
913
925
|
.string()
|
|
914
926
|
.optional()
|
|
915
|
-
.describe(`Channel to send on (${defaultChannel ? `default: ${defaultChannel}` : "REQUIRED: you are on no channel, so there is no default and an omitted channel is refused - join one first"}). Concrete only, not a wildcard like team.>; reply on the channel you received a message on.`),
|
|
927
|
+
.describe(`Channel to send on (${defaultChannel ? `default: ${defaultChannel}` : config.subscribe.some(isConcreteChannel) ? `REQUIRED: ${NO_POSTABLE_DEFAULT}` : "REQUIRED: you are on no channel, so there is no default and an omitted channel is refused - join one first"}). Concrete only, not a wildcard like team.>; reply on the channel you received a message on.`),
|
|
916
928
|
mentions: z
|
|
917
929
|
.array(z.string())
|
|
918
930
|
.optional()
|
|
919
931
|
.describe("Names of peers to call out (e.g. ['bob']). Everyone on the channel still receives the message, but a mentioned peer gets high-priority delivery (eg @bob): woken now if idle, instead of waiting for its next idle moment. Use sparingly: a mention WAKES that peer, so only call someone out when you need THAT specific peer to act now; never mention in an acknowledgement, thanks, or sign-off, or mentions ping-pong between peers and wake the channel in a loop."),
|
|
920
932
|
},
|
|
921
|
-
async run(agent,
|
|
933
|
+
async run(agent, config, { text: msg, channel, mentions }) {
|
|
922
934
|
try {
|
|
923
|
-
const
|
|
935
|
+
const joined = agent.joinedChannels();
|
|
936
|
+
const target = channel ?? defaultSendChannel(config, joined);
|
|
937
|
+
if (target === undefined && joined.some(isConcreteChannel))
|
|
938
|
+
return err(`Couldn't send: ${NO_POSTABLE_DEFAULT}.`);
|
|
924
939
|
const receipt = target !== undefined ? await agent.describeSendChannel(target) : undefined;
|
|
925
|
-
const m = await agent.send(msg,
|
|
940
|
+
const m = await agent.send(msg, target, mentions);
|
|
926
941
|
const dest = `Sent to #${m.channel}${m.mentions?.length ? ` (mentioned @${m.mentions.join(", @")})` : ""}`;
|
|
927
942
|
return ok(receipt ? `${dest} (${receipt}).` : `${dest}.`);
|
|
928
943
|
}
|
|
@@ -1618,6 +1633,7 @@ export function cotalToolSpecs(config, source = "connector", env) {
|
|
|
1618
1633
|
return specs
|
|
1619
1634
|
.filter((spec) => canSpawn || (spec.name !== "cotal_spawn" && spec.name !== "cotal_persona" && spec.name !== "cotal_personas"))
|
|
1620
1635
|
.filter((spec) => canRun || spec.name !== "cotal_run")
|
|
1636
|
+
.filter((spec) => !offered || offered.has(spec.name))
|
|
1621
1637
|
.map((spec) => ({ ...spec, schema: z.strictObject(spec.schema ?? {}) }));
|
|
1622
1638
|
}
|
|
1623
1639
|
//# sourceMappingURL=tool-specs.js.map
|