@calypsohq/elephant-mcp-server 1.3.3 → 1.5.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 +16 -0
- package/dist/ElephantMcpServer.d.ts +45 -0
- package/dist/ElephantMcpServer.js +14 -13
- package/dist/auth/ApiKeyStrategy.d.ts +14 -0
- package/dist/auth/AuthChallenge.d.ts +27 -0
- package/dist/auth/AuthStrategy.d.ts +14 -0
- package/dist/auth/BearerAuthenticator.d.ts +17 -0
- package/dist/auth/Credential.d.ts +23 -0
- package/dist/auth/GrantScopes.d.ts +16 -0
- package/dist/auth/JwtGrantStrategy.d.ts +30 -0
- package/dist/auth/JwtGrantStrategy.js +11 -1
- package/dist/auth/ProtectedResource.d.ts +21 -0
- package/dist/auth/ProtectedResource.js +1 -0
- package/dist/auth/TokenCipher.d.ts +13 -0
- package/dist/calypso/AgentCatalog.d.ts +41 -0
- package/dist/calypso/AgentCatalogLoader.d.ts +12 -0
- package/dist/calypso/AgentChoice.d.ts +25 -0
- package/dist/calypso/AgentResponses.d.ts +47 -0
- package/dist/calypso/AnswerDepth.d.ts +30 -0
- package/dist/calypso/AnswerDiagnostics.d.ts +23 -0
- package/dist/calypso/AnswerSources.d.ts +36 -0
- package/dist/calypso/BatchManifest.d.ts +29 -0
- package/dist/calypso/BucketDestination.d.ts +17 -0
- package/dist/calypso/BucketEdits.d.ts +41 -0
- package/dist/calypso/BucketSources.d.ts +28 -0
- package/dist/calypso/CalypsoApi.d.ts +28 -0
- package/dist/calypso/CalypsoApiClient.d.ts +29 -0
- package/dist/calypso/CalypsoApiConfig.d.ts +15 -0
- package/dist/calypso/KnowledgeBatches.d.ts +25 -0
- package/dist/calypso/KnowledgeBuckets.d.ts +18 -0
- package/dist/calypso/KnowledgeFiles.d.ts +45 -0
- package/dist/calypso/KnowledgeInventory.d.ts +36 -0
- package/dist/calypso/KnowledgeSearch.d.ts +52 -0
- package/dist/calypso/KnowledgeWebsites.d.ts +39 -0
- package/dist/calypso/UploadContent.d.ts +22 -0
- package/dist/calypso/apiErrors.d.ts +14 -0
- package/dist/calypso/bucketList.d.ts +48 -0
- package/dist/calypso/coerce.d.ts +14 -0
- package/dist/calypso/knowledgeTypes.d.ts +64 -0
- package/dist/calypso/polling.d.ts +14 -0
- package/dist/calypso/uploadBytes.d.ts +8 -0
- package/dist/hatching/HatchingCopy.d.ts +11 -0
- package/dist/http/HostedServer.d.ts +8 -0
- package/dist/http/HostedServer.js +10 -0
- package/dist/http/HttpConfig.d.ts +40 -0
- package/dist/http/HttpConfig.js +15 -3
- package/dist/http/HttpServer.d.ts +36 -0
- package/dist/http/KnowledgeInventoryCache.d.ts +21 -0
- package/dist/http/McpEndpoint.d.ts +39 -0
- package/dist/http/McpEndpoint.js +11 -56
- package/dist/http/ModelCatalogCache.d.ts +20 -0
- package/dist/http/ProtectedResourceMetadata.d.ts +19 -0
- package/dist/http/ProtectedResourceMetadata.js +1 -1
- package/dist/http/RateLimiter.d.ts +25 -0
- package/dist/http/StatelessMcpEndpoint.d.ts +40 -0
- package/dist/http/StatelessMcpEndpoint.js +69 -0
- package/dist/index.d.ts +2 -0
- package/dist/kit.d.ts +35 -0
- package/dist/kit.js +31 -0
- package/dist/notices/PostBudget.d.ts +15 -0
- package/dist/notices/PostBudget.js +32 -0
- package/dist/notices/SlackUsageNotices.d.ts +22 -0
- package/dist/notices/SlackUsageNotices.js +57 -0
- package/dist/notices/UsageMessage.d.ts +22 -0
- package/dist/notices/UsageMessage.js +245 -0
- package/dist/notices/UsageNotices.d.ts +25 -0
- package/dist/notices/UsageNotices.js +4 -0
- package/dist/presets/PresetInstructions.d.ts +20 -0
- package/dist/presets/ToolGroup.d.ts +30 -0
- package/dist/presets/ToolGroup.js +4 -0
- package/dist/presets/ToolPreset.d.ts +80 -0
- package/dist/presets/ToolPreset.js +6 -1
- package/dist/presets/ToolPresetRegistry.d.ts +18 -0
- package/dist/stdio/LocalPresets.d.ts +3 -0
- package/dist/stdio/StdioOptions.d.ts +16 -0
- package/dist/stdio.d.ts +2 -0
- package/dist/tools/AddFileTool.d.ts +91 -0
- package/dist/tools/AddFilesTool.d.ts +110 -0
- package/dist/tools/AddWebsiteTool.d.ts +42 -0
- package/dist/tools/AskTool.d.ts +57 -0
- package/dist/tools/CreateBucketTool.d.ts +44 -0
- package/dist/tools/ElephantTool.d.ts +12 -0
- package/dist/tools/ElephantTool.js +6 -36
- package/dist/tools/ListBucketsTool.d.ts +34 -0
- package/dist/tools/McpTool.d.ts +56 -0
- package/dist/tools/McpTool.js +40 -0
- package/dist/tools/MoveSourcesTool.d.ts +30 -0
- package/dist/tools/OpenSourceTool.d.ts +28 -0
- package/dist/tools/RenameBucketTool.d.ts +30 -0
- package/dist/tools/SearchTool.d.ts +36 -0
- package/dist/tools/ToolContext.d.ts +20 -0
- package/dist/tools/ToolLogger.d.ts +17 -0
- package/dist/tools/ToolRegistrar.d.ts +22 -0
- package/dist/tools/ToolRegistrar.js +33 -0
- package/dist/tools/schemaParts.d.ts +38 -0
- package/dist/views/BatchView.d.ts +35 -0
- package/dist/views/BucketView.d.ts +34 -0
- package/dist/views/ErrorView.d.ts +6 -0
- package/dist/views/MoveView.d.ts +20 -0
- package/dist/views/SearchView.d.ts +36 -0
- package/dist/views/SourceView.d.ts +47 -0
- package/dist/views/WebsiteView.d.ts +20 -0
- package/dist/views/viewFields.d.ts +11 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ An unauthenticated request gets `401` with `WWW-Authenticate: Bearer resource_me
|
|
|
59
59
|
| `CALYPSO_API_BASE_URL` | `https://api.calypso.so/v1` | Calypso API |
|
|
60
60
|
| `ELEPHANT_REQUESTS_PER_MINUTE` | `120` | per-caller request budget |
|
|
61
61
|
| `ELEPHANT_OPENAI_CHALLENGE_TOKEN` | — | OpenAI plugin portal domain-verification token, served as plain text at `/.well-known/openai-apps-challenge`; unset answers 404 |
|
|
62
|
+
| `ELEPHANT_SLACK_WEBHOOK_URL` | — | Slack incoming webhook told about each noticed tool call (ask, search, and every tool that adds or organises knowledge; the two inventory tools stay quiet). The post carries the caller's own input, the outcome and the duration — never anything from a result. At most 60 posts a minute per process; unset posts nothing. The stdio server never posts |
|
|
62
63
|
|
|
63
64
|
## Layout
|
|
64
65
|
|
|
@@ -97,6 +98,21 @@ Tools answer with views, not API records. The Calypso API's records also carry w
|
|
|
97
98
|
|
|
98
99
|
Each caller (grant or API key) gets `ELEPHANT_REQUESTS_PER_MINUTE` requests per minute across both endpoints (default 120); over that, `429` with `Retry-After`.
|
|
99
100
|
|
|
101
|
+
## Kit
|
|
102
|
+
|
|
103
|
+
The parts of this server that are not about Elephant are exported as
|
|
104
|
+
`@calypsohq/elephant-mcp-server/kit` ([`src/kit.ts`](src/kit.ts)): bearer authentication against
|
|
105
|
+
Calypso's authorization server, the stateless endpoint (`StatelessMcpEndpoint`), the tool, group
|
|
106
|
+
and preset base classes (`McpTool`, `ToolGroup`, `ToolPreset`), `ToolRegistrar`, the rate limiter,
|
|
107
|
+
`HttpConfig` and the Calypso API client. Another Calypso MCP server builds on these and adds only
|
|
108
|
+
its own tools:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { McpTool, StatelessMcpEndpoint, ToolGroup, ToolPreset } from "@calypsohq/elephant-mcp-server/kit";
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`tests/kit.test.mjs` stands a toy server up from the kit alone and pins the list of exports.
|
|
115
|
+
|
|
100
116
|
## MCP Registry
|
|
101
117
|
|
|
102
118
|
The server is listed in the official [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.calypso-so/elephant-mcp-server`. [`server.json`](./server.json) is what the registry holds: the hosted endpoint and this npm package. Its `name` and `version` must equal `mcpName` and `version` in `package.json` (`tests/registry.test.mjs` keeps them together), so a release bumps both files.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { GrantFacts } from "./auth/Credential.js";
|
|
3
|
+
import type { AgentCatalogSnapshot } from "./calypso/AgentCatalog.js";
|
|
4
|
+
import type { CalypsoApiConfig } from "./calypso/CalypsoApiConfig.js";
|
|
5
|
+
import { type KnowledgeInventorySummary } from "./calypso/KnowledgeInventory.js";
|
|
6
|
+
import { type UsageNotices } from "./notices/UsageNotices.js";
|
|
7
|
+
import type { ToolPreset } from "./presets/ToolPreset.js";
|
|
8
|
+
export type PackageInfo = {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly version: string;
|
|
11
|
+
};
|
|
12
|
+
export type ElephantMcpServerOptions = {
|
|
13
|
+
readonly preset: ToolPreset;
|
|
14
|
+
/** The caller's Calypso API key and the API base URL. */
|
|
15
|
+
readonly api: CalypsoApiConfig;
|
|
16
|
+
/** The caller's agents, already discovered (and cached) by the endpoint. */
|
|
17
|
+
readonly agents: AgentCatalogSnapshot;
|
|
18
|
+
/**
|
|
19
|
+
* What the team has in Elephant, read (and cached) by the endpoint; null
|
|
20
|
+
* when unknown or not read at all, which keeps every behaviour as it was.
|
|
21
|
+
*/
|
|
22
|
+
readonly inventory?: KnowledgeInventorySummary | null;
|
|
23
|
+
readonly packageInfo: PackageInfo;
|
|
24
|
+
/** Safe-to-log label for the caller, e.g. `grant:<id>`. */
|
|
25
|
+
readonly principal: string;
|
|
26
|
+
/**
|
|
27
|
+
* The OAuth scopes the caller's grant carries. Absent or empty (a local
|
|
28
|
+
* server, a raw API key) offers every tool of the preset.
|
|
29
|
+
*/
|
|
30
|
+
readonly scopes?: readonly string[];
|
|
31
|
+
/** The grant's non-secret facts, for the operator notices. */
|
|
32
|
+
readonly grant?: GrantFacts;
|
|
33
|
+
/** Told after each tool call. Absent (stdio, tests), nobody is told. */
|
|
34
|
+
readonly notices?: UsageNotices;
|
|
35
|
+
};
|
|
36
|
+
export declare const GET_STARTED_PROMPT = "elephant-get-started";
|
|
37
|
+
/**
|
|
38
|
+
* Builds the MCP server for one preset and one caller.
|
|
39
|
+
*
|
|
40
|
+
* Built per request and thrown away after it: the tools close over this
|
|
41
|
+
* caller's API client only, so nothing one caller does can reach another.
|
|
42
|
+
* A hatching preset chooses its `instructions` by the team's inventory and
|
|
43
|
+
* publishes the `elephant-get-started` prompt.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createElephantMcpServer(options: ElephantMcpServerOptions): McpServer;
|
|
@@ -4,7 +4,9 @@ import { AgentCatalog } from "./calypso/AgentCatalog.js";
|
|
|
4
4
|
import { CalypsoApi } from "./calypso/CalypsoApi.js";
|
|
5
5
|
import { KnowledgeInventory, } from "./calypso/KnowledgeInventory.js";
|
|
6
6
|
import { hatchingCard, hatchingInstructions } from "./hatching/HatchingCopy.js";
|
|
7
|
+
import { NoUsageNotices, } from "./notices/UsageNotices.js";
|
|
7
8
|
import { ToolLogger } from "./tools/ToolLogger.js";
|
|
9
|
+
import { ToolRegistrar } from "./tools/ToolRegistrar.js";
|
|
8
10
|
export const GET_STARTED_PROMPT = "elephant-get-started";
|
|
9
11
|
/**
|
|
10
12
|
* Builds the MCP server for one preset and one caller.
|
|
@@ -35,24 +37,23 @@ export function createElephantMcpServer(options) {
|
|
|
35
37
|
agents: new AgentCatalog(options.agents),
|
|
36
38
|
inventory: new KnowledgeInventory(inventory, () => api.buckets.list()),
|
|
37
39
|
log: new ToolLogger(server, options.principal),
|
|
40
|
+
notices: options.notices ?? new NoUsageNotices(),
|
|
38
41
|
};
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const caller = {
|
|
43
|
+
principal: options.principal,
|
|
44
|
+
scopes: options.scopes ?? [],
|
|
45
|
+
grant: options.grant,
|
|
46
|
+
};
|
|
47
|
+
for (const tool of preset.toolsFor(grant)) {
|
|
48
|
+
register(server, tool, context, caller);
|
|
49
|
+
}
|
|
41
50
|
if (preset.hatches)
|
|
42
51
|
registerGetStarted(server, context);
|
|
43
52
|
return server;
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
description: tool.description,
|
|
49
|
-
inputSchema: tool.inputSchema,
|
|
50
|
-
...(tool.outputSchema ? { outputSchema: tool.outputSchema } : {}),
|
|
51
|
-
annotations: tool.annotations,
|
|
52
|
-
...(tool.fileParams?.length
|
|
53
|
-
? { _meta: { "openai/fileParams": [...tool.fileParams] } }
|
|
54
|
-
: {}),
|
|
55
|
-
}, (args) => tool.call(args, context));
|
|
54
|
+
/** Registers the tool and tells the notices how each of its calls went. */
|
|
55
|
+
function register(server, tool, context, caller) {
|
|
56
|
+
ToolRegistrar.register(server, tool, context, (report) => context.notices.toolCalled({ ...report, ...caller }));
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* The one prompt: the whole setup for an empty team, a short tour for a team
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthStrategy } from "./AuthStrategy.js";
|
|
2
|
+
import type { Credential } from "./Credential.js";
|
|
3
|
+
/**
|
|
4
|
+
* `Authorization: Bearer sk-…` — a Calypso project API key, passed through.
|
|
5
|
+
*
|
|
6
|
+
* The Calypso API is the authority on whether the key is valid and what it may do, so
|
|
7
|
+
* this strategy only checks the shape; a bad key fails on the first tool call
|
|
8
|
+
* with the API's own error. Keys are accepted only in the header, never in the
|
|
9
|
+
* URL, so they stay out of access logs.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ApiKeyStrategy implements AuthStrategy {
|
|
12
|
+
accepts(token: string): boolean;
|
|
13
|
+
authenticate(token: string): Promise<Credential>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type AuthChallengeError = "invalid_token" | "insufficient_scope";
|
|
2
|
+
/**
|
|
3
|
+
* A refused request, rendered as RFC 6750 / RFC 9728 response.
|
|
4
|
+
*
|
|
5
|
+
* The `resource_metadata` parameter is what lets ChatGPT discover the
|
|
6
|
+
* authorization server from a bare 401, so every challenge on an OAuth
|
|
7
|
+
* preset must carry it.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AuthChallenge {
|
|
10
|
+
readonly status: 401 | 403;
|
|
11
|
+
readonly error: AuthChallengeError | undefined;
|
|
12
|
+
readonly description: string;
|
|
13
|
+
private readonly resourceMetadataUrl;
|
|
14
|
+
private readonly scope;
|
|
15
|
+
private constructor();
|
|
16
|
+
static missing(resourceMetadataUrl?: string): AuthChallenge;
|
|
17
|
+
static invalid(description: string, resourceMetadataUrl?: string): AuthChallenge;
|
|
18
|
+
static insufficientScope(scope: string, resourceMetadataUrl?: string): AuthChallenge;
|
|
19
|
+
/** Value of the `WWW-Authenticate` response header. */
|
|
20
|
+
header(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Why the request was refused, for the request log. Carries the error class
|
|
23
|
+
* and its fixed description only, never anything from the token.
|
|
24
|
+
*/
|
|
25
|
+
logReason(): string;
|
|
26
|
+
body(): Record<string, string>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AuthChallenge } from "./AuthChallenge.js";
|
|
2
|
+
import type { Credential } from "./Credential.js";
|
|
3
|
+
import type { ProtectedResource } from "./ProtectedResource.js";
|
|
4
|
+
/**
|
|
5
|
+
* One way of turning a bearer token into a Credential.
|
|
6
|
+
*
|
|
7
|
+
* `accepts` is a cheap shape check so the authenticator can pick the strategy
|
|
8
|
+
* without trying each one; `authenticate` does the real verification and
|
|
9
|
+
* returns either a Credential or the challenge to send back.
|
|
10
|
+
*/
|
|
11
|
+
export interface AuthStrategy {
|
|
12
|
+
accepts(token: string): boolean;
|
|
13
|
+
authenticate(token: string, preset: ProtectedResource): Promise<Credential | AuthChallenge>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AuthChallenge } from "./AuthChallenge.js";
|
|
2
|
+
import type { AuthStrategy } from "./AuthStrategy.js";
|
|
3
|
+
import type { Credential } from "./Credential.js";
|
|
4
|
+
import type { ProtectedResource } from "./ProtectedResource.js";
|
|
5
|
+
/**
|
|
6
|
+
* Picks the strategy that recognizes the bearer token and runs it.
|
|
7
|
+
*
|
|
8
|
+
* No token, or one no strategy recognizes, yields the 401 that starts OAuth
|
|
9
|
+
* discovery for presets that support it.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BearerAuthenticator {
|
|
12
|
+
private readonly strategies;
|
|
13
|
+
private readonly resourceMetadataUrl;
|
|
14
|
+
constructor(strategies: readonly AuthStrategy[], resourceMetadataUrl: (preset: ProtectedResource) => string | undefined);
|
|
15
|
+
authenticate(authorization: string | undefined, preset: ProtectedResource): Promise<Credential | AuthChallenge>;
|
|
16
|
+
private static bearerToken;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The non-secret facts of an OAuth grant, for logs and operator notices:
|
|
3
|
+
* which grant, which team, which client, which person. Never the key.
|
|
4
|
+
*/
|
|
5
|
+
export type GrantFacts = {
|
|
6
|
+
readonly gid: string;
|
|
7
|
+
readonly team?: string;
|
|
8
|
+
readonly cid?: string;
|
|
9
|
+
readonly sub?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* What an authenticated request carries into the tool layer: the Calypso API
|
|
13
|
+
* key every tool call is made with, and a non-secret label for logs.
|
|
14
|
+
*/
|
|
15
|
+
export type Credential = {
|
|
16
|
+
readonly apiKey: string;
|
|
17
|
+
/** Safe to log: `grant:<gid>` or `key:sk-…abcd`. Never the key itself. */
|
|
18
|
+
readonly principal: string;
|
|
19
|
+
/** OAuth scopes granted, empty for raw API keys (which carry all). */
|
|
20
|
+
readonly scopes: readonly string[];
|
|
21
|
+
/** Present for an OAuth grant; a raw API key has none. */
|
|
22
|
+
readonly grant?: GrantFacts;
|
|
23
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ToolGroup } from "../presets/ToolGroup.js";
|
|
2
|
+
/**
|
|
3
|
+
* What one caller agreed to, as the tool layer needs to ask it.
|
|
4
|
+
*
|
|
5
|
+
* An OAuth grant lists its scopes. A raw API key lists none: the Calypso API
|
|
6
|
+
* is the authority on what that key may do, so every tool is offered and a
|
|
7
|
+
* call the key cannot make fails with the API's own error.
|
|
8
|
+
*/
|
|
9
|
+
export declare class GrantScopes {
|
|
10
|
+
private readonly scopes;
|
|
11
|
+
private constructor();
|
|
12
|
+
/** Everything: a local server, or a key whose limits the API enforces. */
|
|
13
|
+
static everything(): GrantScopes;
|
|
14
|
+
static of(scopes: readonly string[] | undefined): GrantScopes;
|
|
15
|
+
allows(group: ToolGroup): boolean;
|
|
16
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type JWTVerifyGetKey } from "jose";
|
|
2
|
+
import { AuthChallenge } from "./AuthChallenge.js";
|
|
3
|
+
import type { AuthStrategy } from "./AuthStrategy.js";
|
|
4
|
+
import type { Credential } from "./Credential.js";
|
|
5
|
+
import type { ProtectedResource } from "./ProtectedResource.js";
|
|
6
|
+
import type { TokenCipher } from "./TokenCipher.js";
|
|
7
|
+
export type JwtGrantStrategyOptions = {
|
|
8
|
+
issuer: string;
|
|
9
|
+
/** JWKS resolver, normally `createRemoteJWKSet(issuer/.well-known/jwks.json)`. */
|
|
10
|
+
keys: JWTVerifyGetKey;
|
|
11
|
+
cipher: TokenCipher;
|
|
12
|
+
/** Public base URL of this server; `aud` must be base + preset path. */
|
|
13
|
+
publicBaseUrl: string;
|
|
14
|
+
/** Builds the challenge's resource_metadata URL for a preset. */
|
|
15
|
+
resourceMetadataUrl: (preset: ProtectedResource) => string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Access tokens issued by the Elephant authorization server (login.calypso.so).
|
|
19
|
+
*
|
|
20
|
+
* Verifies signature, issuer, audience (exactly this preset's URL — a token
|
|
21
|
+
* for /elephant/mcp is useless on /elephant/builder/mcp), expiry and scope,
|
|
22
|
+
* then unseals the grant's API key from `ek`. The server keeps no grant state:
|
|
23
|
+
* revoking a grant revokes its key, which the Calypso API then rejects.
|
|
24
|
+
*/
|
|
25
|
+
export declare class JwtGrantStrategy implements AuthStrategy {
|
|
26
|
+
private readonly options;
|
|
27
|
+
constructor(options: JwtGrantStrategyOptions);
|
|
28
|
+
accepts(token: string): boolean;
|
|
29
|
+
authenticate(token: string, preset: ProtectedResource): Promise<Credential | AuthChallenge>;
|
|
30
|
+
}
|
|
@@ -45,7 +45,17 @@ export class JwtGrantStrategy {
|
|
|
45
45
|
catch {
|
|
46
46
|
return AuthChallenge.invalid("The access token is malformed.", metadataUrl);
|
|
47
47
|
}
|
|
48
|
-
return {
|
|
48
|
+
return {
|
|
49
|
+
apiKey,
|
|
50
|
+
principal: `grant:${claims.gid}`,
|
|
51
|
+
scopes,
|
|
52
|
+
grant: {
|
|
53
|
+
gid: String(claims.gid),
|
|
54
|
+
team: claims.team,
|
|
55
|
+
cid: claims.cid,
|
|
56
|
+
sub: claims.sub,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
61
|
function describeJoseError(error) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What authentication and discovery need to know about one MCP endpoint.
|
|
3
|
+
*
|
|
4
|
+
* A preset is the usual implementation. Naming only these members keeps the
|
|
5
|
+
* bearer checks and the protected-resource metadata free of any one product's
|
|
6
|
+
* tools, so another Calypso server can be protected by the same classes.
|
|
7
|
+
*/
|
|
8
|
+
export interface ProtectedResource {
|
|
9
|
+
/** HTTP path the endpoint is served on, e.g. `/elephant/mcp`. */
|
|
10
|
+
readonly path: string;
|
|
11
|
+
/** OAuth scope a bearer token must carry to connect at all. */
|
|
12
|
+
readonly scope: string;
|
|
13
|
+
/** Human name shown on consent and in protected-resource metadata. */
|
|
14
|
+
readonly displayName: string;
|
|
15
|
+
/** Where the product is documented; the metadata links to it. */
|
|
16
|
+
readonly documentationUrl?: string;
|
|
17
|
+
/** Every OAuth scope a grant for this endpoint may carry. */
|
|
18
|
+
scopes(): string[];
|
|
19
|
+
/** Absolute resource URL (`aud`) under a public base URL. */
|
|
20
|
+
resourceUrl(publicBaseUrl: string): string;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AES-256-GCM sealing for the `ek` access-token claim.
|
|
3
|
+
*
|
|
4
|
+
* Wire format (shared with the authorization server in web-app-new):
|
|
5
|
+
* `base64url(iv[12]) "." base64url(ciphertext ‖ tag[16])`.
|
|
6
|
+
* The key is 32 bytes, configured base64-encoded in ELEPHANT_TOKEN_ENC_KEY.
|
|
7
|
+
*/
|
|
8
|
+
export declare class TokenCipher {
|
|
9
|
+
private readonly key;
|
|
10
|
+
constructor(base64Key: string);
|
|
11
|
+
seal(plaintext: string): string;
|
|
12
|
+
open(sealed: string): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type AgentBucketDescriptor = {
|
|
2
|
+
id: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
slug?: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
member_count?: number;
|
|
7
|
+
};
|
|
8
|
+
export type AgentDescriptor = {
|
|
9
|
+
id: string;
|
|
10
|
+
base_model?: string;
|
|
11
|
+
profile_id?: string | null;
|
|
12
|
+
source?: string;
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
bucket_ids: string[];
|
|
15
|
+
buckets: AgentBucketDescriptor[];
|
|
16
|
+
missing_bucket_ids: string[];
|
|
17
|
+
};
|
|
18
|
+
/** The team's agents as discovery returned them, or the fallback list. */
|
|
19
|
+
export type AgentCatalogSnapshot = {
|
|
20
|
+
models: AgentDescriptor[];
|
|
21
|
+
defaultModel: string;
|
|
22
|
+
fetchedAt: string | null;
|
|
23
|
+
source: "api" | "fallback";
|
|
24
|
+
error?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The agents a caller may ask, and which one answers by default.
|
|
28
|
+
*
|
|
29
|
+
* Tools read the catalog through this accessor rather than the raw snapshot so
|
|
30
|
+
* the rule "only ids discovery lists are accepted" lives in one place. An
|
|
31
|
+
* unknown id fails loudly and names the alternatives, which lets the model
|
|
32
|
+
* correct itself instead of the API answering with an opaque 404.
|
|
33
|
+
*/
|
|
34
|
+
export declare class AgentCatalog {
|
|
35
|
+
private readonly snapshot;
|
|
36
|
+
constructor(snapshot: AgentCatalogSnapshot);
|
|
37
|
+
get defaultAgentId(): string;
|
|
38
|
+
ids(): string[];
|
|
39
|
+
/** The requested agent id, or the default when none was requested. */
|
|
40
|
+
resolve(requested?: string): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AgentCatalogSnapshot } from "./AgentCatalog.js";
|
|
2
|
+
import type { CalypsoApiConfig } from "./CalypsoApiConfig.js";
|
|
3
|
+
/** The catalog used when discovery cannot be reached: the base agent alone. */
|
|
4
|
+
export declare function fallbackAgentCatalog(error?: unknown): AgentCatalogSnapshot;
|
|
5
|
+
/**
|
|
6
|
+
* Loads the team's agents from `GET /rag-agent/models`.
|
|
7
|
+
*
|
|
8
|
+
* Never rejects: any failure (no key, timeout, non-2xx, malformed body)
|
|
9
|
+
* yields the fallback catalog, because a discovery outage must not take the
|
|
10
|
+
* tools down with it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadAgentCatalog(config: CalypsoApiConfig): Promise<AgentCatalogSnapshot>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AgentCatalog } from "./AgentCatalog.js";
|
|
2
|
+
/**
|
|
3
|
+
* The agent a connection asks when the caller names none: the team's default
|
|
4
|
+
* agent reading every bucket the team has, decided per question by the API.
|
|
5
|
+
* A bucket created through Elephant is answerable from the next question on,
|
|
6
|
+
* which a stored agent (linked to at most five chosen buckets) cannot promise.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CONNECTOR_AGENT_ID = "elephant-agent:mcp";
|
|
9
|
+
/**
|
|
10
|
+
* Which agent answers this call, and what to fall back to.
|
|
11
|
+
*
|
|
12
|
+
* A caller that names an agent gets exactly that one, checked against the
|
|
13
|
+
* catalog. A caller that names none gets the connector agent, with the
|
|
14
|
+
* catalog's default behind it for an API that does not know the connector
|
|
15
|
+
* agent yet, so the server can be deployed before or after the API.
|
|
16
|
+
*/
|
|
17
|
+
export declare class AgentChoice {
|
|
18
|
+
readonly agentId: string;
|
|
19
|
+
readonly fallbackId: string | null;
|
|
20
|
+
private constructor();
|
|
21
|
+
static of(catalog: AgentCatalog, requested?: string): AgentChoice;
|
|
22
|
+
get isConnector(): boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Whether an API error says the agent itself is unknown, not something in the request. */
|
|
25
|
+
export declare function isUnknownAgent(error: unknown): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AnswerDepth } from "./AnswerDepth.js";
|
|
2
|
+
import { AnswerDiagnostics } from "./AnswerDiagnostics.js";
|
|
3
|
+
import { AnswerSources } from "./AnswerSources.js";
|
|
4
|
+
import { type CalypsoApiConfig } from "./CalypsoApiConfig.js";
|
|
5
|
+
export type AgentQuestion = {
|
|
6
|
+
/** Agent that answers, already checked against the catalog. */
|
|
7
|
+
readonly agentId: string;
|
|
8
|
+
readonly prompt: string;
|
|
9
|
+
/** Sources to focus the answer on. */
|
|
10
|
+
readonly fileIds?: readonly string[];
|
|
11
|
+
/** Names the conversation this single turn opens. */
|
|
12
|
+
readonly conversationId: string;
|
|
13
|
+
/** How much work the answer is worth; the agent's own default when absent. */
|
|
14
|
+
readonly depth?: AnswerDepth;
|
|
15
|
+
/** Bucket ids or slugs to limit this answer to, up to five. */
|
|
16
|
+
readonly buckets?: readonly string[];
|
|
17
|
+
};
|
|
18
|
+
export type AgentAnswer = {
|
|
19
|
+
readonly text: string;
|
|
20
|
+
readonly responseId: string | null;
|
|
21
|
+
/** What the answer was grounded in; empty when the response names none. */
|
|
22
|
+
readonly sources: AnswerSources;
|
|
23
|
+
/** The depth the API reports it answered at, which a plan may cap. */
|
|
24
|
+
readonly depth?: AnswerDepth;
|
|
25
|
+
/** Why retrieval could not run as asked, and which buckets were left out. */
|
|
26
|
+
readonly diagnostics: AnswerDiagnostics;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Asks a Calypso agent through the OpenAI-compatible `POST /responses`.
|
|
30
|
+
*
|
|
31
|
+
* Each question is its own conversation. The server is stateless (every HTTP
|
|
32
|
+
* request builds a fresh one), so there is nowhere to keep a thread between
|
|
33
|
+
* calls and a follow-up must carry its own context in the prompt.
|
|
34
|
+
*/
|
|
35
|
+
export declare class AgentResponses {
|
|
36
|
+
private readonly config;
|
|
37
|
+
private readonly userAgent;
|
|
38
|
+
private client;
|
|
39
|
+
constructor(config: CalypsoApiConfig, userAgent: string);
|
|
40
|
+
static newConversationId(): string;
|
|
41
|
+
ask(question: AgentQuestion): Promise<AgentAnswer>;
|
|
42
|
+
private openai;
|
|
43
|
+
private static requestFor;
|
|
44
|
+
private static metadataFor;
|
|
45
|
+
/** Folds the event stream into the answer text, its sources and the response id. */
|
|
46
|
+
private static collect;
|
|
47
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The depths a caller may ask for, shallowest first. */
|
|
2
|
+
export declare const ANSWER_DEPTHS: readonly ["fast", "balanced", "deep"];
|
|
3
|
+
export type AnswerDepthName = (typeof ANSWER_DEPTHS)[number];
|
|
4
|
+
/** The depths a search may run at. */
|
|
5
|
+
export declare const SEARCH_DEPTHS: readonly ["fast", "thorough"];
|
|
6
|
+
export type SearchDepthName = (typeof SEARCH_DEPTHS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* How much work an answer is worth: which Calypso response tier writes it.
|
|
9
|
+
*
|
|
10
|
+
* Callers pick a depth in plain words; the Calypso API speaks in response
|
|
11
|
+
* policies (`fast`, `medium`, `extended`) and reports the tier it actually
|
|
12
|
+
* used as an OpenAI reasoning effort. This class is the only place that knows
|
|
13
|
+
* both vocabularies, so a tool never has to.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AnswerDepth {
|
|
16
|
+
readonly name: AnswerDepthName;
|
|
17
|
+
/** The `response_policy` the Calypso API takes. */
|
|
18
|
+
readonly responsePolicy: "fast" | "medium" | "extended";
|
|
19
|
+
private readonly efforts;
|
|
20
|
+
private static readonly ALL;
|
|
21
|
+
private constructor();
|
|
22
|
+
/** The depth a caller named; undefined when none was asked for. */
|
|
23
|
+
static named(name: string | undefined): AnswerDepth | undefined;
|
|
24
|
+
/** The depth a finished response says it ran at, from its reasoning effort. */
|
|
25
|
+
static used(response: unknown): AnswerDepth | undefined;
|
|
26
|
+
/** Whether this depth does less work than the other. */
|
|
27
|
+
isShallowerThan(other: AnswerDepth): boolean;
|
|
28
|
+
}
|
|
29
|
+
/** The search depth the Calypso API takes for a caller's word. */
|
|
30
|
+
export declare function searchDepthForApi(depth: SearchDepthName | undefined, extraQueries: number): "fast" | "standard" | undefined;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the API says about how an answer was produced, beyond its text:
|
|
3
|
+
* `metadata._aicore.answer_failure_code` when retrieval could not run as
|
|
4
|
+
* asked, and `metadata._aicore.bucket_coverage` when some buckets in scope
|
|
5
|
+
* were not read.
|
|
6
|
+
*
|
|
7
|
+
* Without this, a refusal with a precise cause ("that source is in a bucket
|
|
8
|
+
* this agent does not read") reaches the caller as the generic "not enough
|
|
9
|
+
* information", and the caller concludes the knowledge is missing.
|
|
10
|
+
*/
|
|
11
|
+
export type BucketCoverage = {
|
|
12
|
+
readonly searched: readonly string[];
|
|
13
|
+
readonly unsearched: readonly string[];
|
|
14
|
+
};
|
|
15
|
+
export declare class AnswerDiagnostics {
|
|
16
|
+
readonly failureCode: string | null;
|
|
17
|
+
readonly coverage: BucketCoverage | null;
|
|
18
|
+
private constructor();
|
|
19
|
+
static none(): AnswerDiagnostics;
|
|
20
|
+
static fromResponse(response: unknown): AnswerDiagnostics;
|
|
21
|
+
/** What to tell the caller instead of the answer text, when retrieval could not run. */
|
|
22
|
+
failureReason(): string | null;
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** One source an answer was grounded in, as a reader should see it. */
|
|
2
|
+
export type AnswerSource = {
|
|
3
|
+
/** File name, page title or URL: what the source is called. */
|
|
4
|
+
readonly label: string;
|
|
5
|
+
/** The source's id, usable with `elephant-open-source`. */
|
|
6
|
+
readonly fileId?: string;
|
|
7
|
+
readonly url?: string;
|
|
8
|
+
/** Where in the source, when the answer names a place ("p. 4"). */
|
|
9
|
+
readonly locator?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The sources a completed agent response says it used.
|
|
13
|
+
*
|
|
14
|
+
* The Calypso API streams the answer as text and reports its sources on the
|
|
15
|
+
* finished response, not inside the text: in `metadata._aicore.grounded_sources`
|
|
16
|
+
* and as `annotations` on the output text. A reader of the text alone sees an
|
|
17
|
+
* answer with no source, so they are read here and written out under it.
|
|
18
|
+
*/
|
|
19
|
+
export declare class AnswerSources {
|
|
20
|
+
readonly items: readonly AnswerSource[];
|
|
21
|
+
private constructor();
|
|
22
|
+
/** No sources: an answer that names none, or one not finished yet. */
|
|
23
|
+
static none(): AnswerSources;
|
|
24
|
+
/** Sources of a `response.completed` payload; empty when it names none. */
|
|
25
|
+
static fromResponse(response: unknown): AnswerSources;
|
|
26
|
+
get count(): number;
|
|
27
|
+
/** The block appended under an answer; empty when there are no sources. */
|
|
28
|
+
render(): string;
|
|
29
|
+
private static fromGroundedSources;
|
|
30
|
+
private static fromAnnotations;
|
|
31
|
+
/** One line per source and place: a file cited five times is listed once. */
|
|
32
|
+
private static distinct;
|
|
33
|
+
private static object;
|
|
34
|
+
private static list;
|
|
35
|
+
private static text;
|
|
36
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type BucketDestination } from "./BucketDestination.js";
|
|
2
|
+
export declare const BATCH_MAX_FILES = 100;
|
|
3
|
+
export type BatchItemParams = BucketDestination & {
|
|
4
|
+
filename: string;
|
|
5
|
+
mimeType: string;
|
|
6
|
+
contentBase64?: string;
|
|
7
|
+
clientFileId?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
tags?: string[];
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
export type UploadKnowledgeFilesBatchParams = BucketDestination & {
|
|
13
|
+
items: BatchItemParams[];
|
|
14
|
+
batchIdempotencyKey: string;
|
|
15
|
+
waitForBatchReady?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type BatchManifest = {
|
|
18
|
+
manifest: Record<string, unknown>;
|
|
19
|
+
/** One id per item, in item order; how sessions are matched back to files. */
|
|
20
|
+
clientFileIds: string[];
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Describes a batch to Calypso before any bytes move.
|
|
24
|
+
*
|
|
25
|
+
* Everything that can be refused without a network call is refused here, so a
|
|
26
|
+
* batch of a hundred files does not fail on item ninety after uploading the
|
|
27
|
+
* rest.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildKnowledgeBatchManifest(params: UploadKnowledgeFilesBatchParams): BatchManifest;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an upload goes: bucket ids, bucket slugs, or one slug as a shortcut.
|
|
3
|
+
*
|
|
4
|
+
* Every write needs a destination, because knowledge outside a bucket cannot
|
|
5
|
+
* be searched or asked about.
|
|
6
|
+
*/
|
|
7
|
+
export type BucketDestination = {
|
|
8
|
+
bucketIds?: string[];
|
|
9
|
+
bucketSlugs?: string[];
|
|
10
|
+
bucket?: string;
|
|
11
|
+
createMissingBuckets?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function hasBucketDestination(source: BucketDestination): boolean;
|
|
14
|
+
/** How many destinations were named; a count is safe to log, names are not. */
|
|
15
|
+
export declare function countBucketTargets(source: BucketDestination): number;
|
|
16
|
+
/** The destination as the snake_case fields the upload endpoints take. */
|
|
17
|
+
export declare function bucketFields(source: BucketDestination): Record<string, unknown>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CalypsoApiClient } from "./CalypsoApiClient.js";
|
|
2
|
+
export type BucketRename = {
|
|
3
|
+
/** The bucket to change: its id or its slug. */
|
|
4
|
+
bucket: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
};
|
|
8
|
+
export type SourceMove = {
|
|
9
|
+
sourceIds: string[];
|
|
10
|
+
/** Bucket the sources are taken out of: id or slug. */
|
|
11
|
+
fromBucket: string;
|
|
12
|
+
/** Bucket the sources go into: id or slug. */
|
|
13
|
+
toBucket: string;
|
|
14
|
+
};
|
|
15
|
+
export type SourceMoveResult = {
|
|
16
|
+
bucket_id?: string;
|
|
17
|
+
from_bucket_id?: string;
|
|
18
|
+
moved: number;
|
|
19
|
+
requested: number;
|
|
20
|
+
/** One entry per source: `moved`, or why it was not. */
|
|
21
|
+
sources: Array<{
|
|
22
|
+
id: string;
|
|
23
|
+
status: string;
|
|
24
|
+
detail?: string;
|
|
25
|
+
}>;
|
|
26
|
+
request_id?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Reorganising what is already saved: a bucket's name and note, and which
|
|
30
|
+
* bucket a source is filed in. Nothing here adds or deletes a source.
|
|
31
|
+
*/
|
|
32
|
+
export declare class BucketEdits {
|
|
33
|
+
private readonly api;
|
|
34
|
+
constructor(api: CalypsoApiClient);
|
|
35
|
+
rename(input: BucketRename): Promise<Record<string, unknown>>;
|
|
36
|
+
/**
|
|
37
|
+
* Moves sources into `toBucket`. The API adds each one there before taking
|
|
38
|
+
* it out of `fromBucket`, so a source is never left in no bucket.
|
|
39
|
+
*/
|
|
40
|
+
moveSources(input: SourceMove): Promise<SourceMoveResult>;
|
|
41
|
+
}
|