@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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
waitForBatchReady: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
bucketIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
bucketSlugs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
9
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
10
|
+
createMissingBuckets: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
items: z.ZodArray<z.ZodObject<{
|
|
12
|
+
bucketIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
13
|
+
bucketSlugs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
14
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
15
|
+
createMissingBuckets: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
filename: z.ZodString;
|
|
17
|
+
mimeType: z.ZodString;
|
|
18
|
+
contentBase64: z.ZodString;
|
|
19
|
+
clientFileId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
title: z.ZodOptional<z.ZodString>;
|
|
21
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
22
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
filename: string;
|
|
25
|
+
mimeType: string;
|
|
26
|
+
contentBase64: string;
|
|
27
|
+
metadata?: Record<string, unknown> | undefined;
|
|
28
|
+
title?: string | undefined;
|
|
29
|
+
bucket?: string | undefined;
|
|
30
|
+
tags?: string[] | undefined;
|
|
31
|
+
clientFileId?: string | undefined;
|
|
32
|
+
bucketIds?: string[] | undefined;
|
|
33
|
+
bucketSlugs?: string[] | undefined;
|
|
34
|
+
createMissingBuckets?: boolean | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
filename: string;
|
|
37
|
+
mimeType: string;
|
|
38
|
+
contentBase64: string;
|
|
39
|
+
metadata?: Record<string, unknown> | undefined;
|
|
40
|
+
title?: string | undefined;
|
|
41
|
+
bucket?: string | undefined;
|
|
42
|
+
tags?: string[] | undefined;
|
|
43
|
+
clientFileId?: string | undefined;
|
|
44
|
+
bucketIds?: string[] | undefined;
|
|
45
|
+
bucketSlugs?: string[] | undefined;
|
|
46
|
+
createMissingBuckets?: boolean | undefined;
|
|
47
|
+
}>, "many">;
|
|
48
|
+
batchIdempotencyKey: z.ZodOptional<z.ZodString>;
|
|
49
|
+
};
|
|
50
|
+
/** `elephant-add-files`: up to a hundred files in one request. */
|
|
51
|
+
export declare class AddFilesTool extends ElephantTool<typeof inputSchema> {
|
|
52
|
+
readonly name = "elephant-add-files";
|
|
53
|
+
readonly title = "Add files";
|
|
54
|
+
readonly description: string;
|
|
55
|
+
readonly inputSchema: {
|
|
56
|
+
waitForBatchReady: z.ZodOptional<z.ZodBoolean>;
|
|
57
|
+
bucketIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
58
|
+
bucketSlugs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
59
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
60
|
+
createMissingBuckets: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
items: z.ZodArray<z.ZodObject<{
|
|
62
|
+
bucketIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
63
|
+
bucketSlugs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
64
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
65
|
+
createMissingBuckets: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
filename: z.ZodString;
|
|
67
|
+
mimeType: z.ZodString;
|
|
68
|
+
contentBase64: z.ZodString;
|
|
69
|
+
clientFileId: z.ZodOptional<z.ZodString>;
|
|
70
|
+
title: z.ZodOptional<z.ZodString>;
|
|
71
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
72
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
73
|
+
}, "strip", z.ZodTypeAny, {
|
|
74
|
+
filename: string;
|
|
75
|
+
mimeType: string;
|
|
76
|
+
contentBase64: string;
|
|
77
|
+
metadata?: Record<string, unknown> | undefined;
|
|
78
|
+
title?: string | undefined;
|
|
79
|
+
bucket?: string | undefined;
|
|
80
|
+
tags?: string[] | undefined;
|
|
81
|
+
clientFileId?: string | undefined;
|
|
82
|
+
bucketIds?: string[] | undefined;
|
|
83
|
+
bucketSlugs?: string[] | undefined;
|
|
84
|
+
createMissingBuckets?: boolean | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
filename: string;
|
|
87
|
+
mimeType: string;
|
|
88
|
+
contentBase64: string;
|
|
89
|
+
metadata?: Record<string, unknown> | undefined;
|
|
90
|
+
title?: string | undefined;
|
|
91
|
+
bucket?: string | undefined;
|
|
92
|
+
tags?: string[] | undefined;
|
|
93
|
+
clientFileId?: string | undefined;
|
|
94
|
+
bucketIds?: string[] | undefined;
|
|
95
|
+
bucketSlugs?: string[] | undefined;
|
|
96
|
+
createMissingBuckets?: boolean | undefined;
|
|
97
|
+
}>, "many">;
|
|
98
|
+
batchIdempotencyKey: z.ZodOptional<z.ZodString>;
|
|
99
|
+
};
|
|
100
|
+
readonly group: ToolGroup;
|
|
101
|
+
readonly annotations: {
|
|
102
|
+
readOnlyHint: boolean;
|
|
103
|
+
destructiveHint: boolean;
|
|
104
|
+
idempotentHint: boolean;
|
|
105
|
+
openWorldHint: boolean;
|
|
106
|
+
};
|
|
107
|
+
protected readonly failure = "Adding the files failed.";
|
|
108
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, log }: ToolContext): Promise<ToolOutput>;
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
7
|
+
bucketIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
bucketSlugs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
9
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
10
|
+
createMissingBuckets: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
url: z.ZodString;
|
|
12
|
+
title: z.ZodOptional<z.ZodString>;
|
|
13
|
+
tagsHint: z.ZodOptional<z.ZodString>;
|
|
14
|
+
preferredLanguage: z.ZodOptional<z.ZodString>;
|
|
15
|
+
};
|
|
16
|
+
/** `elephant-add-website`: a web page into a bucket. */
|
|
17
|
+
export declare class AddWebsiteTool extends ElephantTool<typeof inputSchema> {
|
|
18
|
+
readonly name = "elephant-add-website";
|
|
19
|
+
readonly title = "Add a website";
|
|
20
|
+
readonly description: string;
|
|
21
|
+
readonly inputSchema: {
|
|
22
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
23
|
+
bucketIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
24
|
+
bucketSlugs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
25
|
+
bucket: z.ZodOptional<z.ZodString>;
|
|
26
|
+
createMissingBuckets: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
url: z.ZodString;
|
|
28
|
+
title: z.ZodOptional<z.ZodString>;
|
|
29
|
+
tagsHint: z.ZodOptional<z.ZodString>;
|
|
30
|
+
preferredLanguage: z.ZodOptional<z.ZodString>;
|
|
31
|
+
};
|
|
32
|
+
readonly group: ToolGroup;
|
|
33
|
+
readonly annotations: {
|
|
34
|
+
readOnlyHint: boolean;
|
|
35
|
+
destructiveHint: boolean;
|
|
36
|
+
idempotentHint: boolean;
|
|
37
|
+
openWorldHint: boolean;
|
|
38
|
+
};
|
|
39
|
+
protected readonly failure = "Adding the website failed.";
|
|
40
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, log }: ToolContext): Promise<ToolOutput>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
prompt: z.ZodString;
|
|
7
|
+
fileIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
8
|
+
model: z.ZodOptional<z.ZodString>;
|
|
9
|
+
buckets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
10
|
+
depth: z.ZodOptional<z.ZodEnum<["fast", "balanced", "deep"]>>;
|
|
11
|
+
};
|
|
12
|
+
/** `elephant-ask`: a cited answer written from the team's knowledge. */
|
|
13
|
+
export declare class AskTool extends ElephantTool<typeof inputSchema> {
|
|
14
|
+
readonly name = "elephant-ask";
|
|
15
|
+
readonly title = "Ask Elephant";
|
|
16
|
+
readonly description: string;
|
|
17
|
+
readonly inputSchema: {
|
|
18
|
+
prompt: z.ZodString;
|
|
19
|
+
fileIds: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
20
|
+
model: z.ZodOptional<z.ZodString>;
|
|
21
|
+
buckets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
22
|
+
depth: z.ZodOptional<z.ZodEnum<["fast", "balanced", "deep"]>>;
|
|
23
|
+
};
|
|
24
|
+
readonly group: ToolGroup;
|
|
25
|
+
readonly annotations: {
|
|
26
|
+
readOnlyHint: boolean;
|
|
27
|
+
destructiveHint: boolean;
|
|
28
|
+
openWorldHint: boolean;
|
|
29
|
+
};
|
|
30
|
+
protected readonly failure = "Elephant could not answer.";
|
|
31
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, agents, inventory, log }: ToolContext): Promise<ToolOutput>;
|
|
32
|
+
/**
|
|
33
|
+
* The connector agent first; the catalog's default when this API does not
|
|
34
|
+
* know it yet. Only an "unknown agent" answer falls back: anything else is
|
|
35
|
+
* the real outcome of the question.
|
|
36
|
+
*/
|
|
37
|
+
private static askWithFallback;
|
|
38
|
+
/**
|
|
39
|
+
* One line naming the buckets the answer did not read, when there were
|
|
40
|
+
* more than one answer reads. Names come from the bucket list; an id is
|
|
41
|
+
* shown when a name cannot be read.
|
|
42
|
+
*/
|
|
43
|
+
private static coverageNote;
|
|
44
|
+
/**
|
|
45
|
+
* One closing line saying the depth the answer got, so the caller knows
|
|
46
|
+
* what a retry one step higher would buy, and when a plan capped the ask.
|
|
47
|
+
*/
|
|
48
|
+
private static depthNote;
|
|
49
|
+
/**
|
|
50
|
+
* A file id the API does not know arrives as a bare 404. Say what it means
|
|
51
|
+
* and what to do, since "404 status code (no body)" tells the caller nothing.
|
|
52
|
+
*/
|
|
53
|
+
private static readable;
|
|
54
|
+
/** Whether the answer text already ends in its own list of sources. */
|
|
55
|
+
private static namesItsSources;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
8
|
+
description: z.ZodOptional<z.ZodString>;
|
|
9
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
10
|
+
};
|
|
11
|
+
/** `elephant-create-bucket`: a new, empty folder of sources. */
|
|
12
|
+
export declare class CreateBucketTool extends ElephantTool<typeof inputSchema> {
|
|
13
|
+
readonly name = "elephant-create-bucket";
|
|
14
|
+
readonly title = "Create a bucket";
|
|
15
|
+
readonly description: string;
|
|
16
|
+
readonly inputSchema: {
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
19
|
+
description: z.ZodOptional<z.ZodString>;
|
|
20
|
+
idempotencyKey: z.ZodOptional<z.ZodString>;
|
|
21
|
+
};
|
|
22
|
+
readonly group: ToolGroup;
|
|
23
|
+
readonly outputSchema: {
|
|
24
|
+
id: z.ZodOptional<z.ZodString>;
|
|
25
|
+
name: z.ZodOptional<z.ZodString>;
|
|
26
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
27
|
+
status: z.ZodOptional<z.ZodString>;
|
|
28
|
+
};
|
|
29
|
+
readonly annotations: {
|
|
30
|
+
readOnlyHint: boolean;
|
|
31
|
+
destructiveHint: boolean;
|
|
32
|
+
idempotentHint: boolean;
|
|
33
|
+
openWorldHint: boolean;
|
|
34
|
+
};
|
|
35
|
+
protected readonly failure = "Creating the bucket failed.";
|
|
36
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, log }: ToolContext): Promise<ToolOutput>;
|
|
37
|
+
/**
|
|
38
|
+
* Structured output is checked strictly against `outputSchema`: only the
|
|
39
|
+
* declared fields go in the structured part. The text carries the bucket's
|
|
40
|
+
* view, which also has its description.
|
|
41
|
+
*/
|
|
42
|
+
private static declaredFields;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type InputShape, McpTool } from "./McpTool.js";
|
|
2
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
3
|
+
export type { InputShape, ToolArgs, ToolOutput } from "./McpTool.js";
|
|
4
|
+
/**
|
|
5
|
+
* One Elephant tool: a tool handed Elephant's context (the Calypso API as the
|
|
6
|
+
* caller, their agents, their knowledge inventory).
|
|
7
|
+
*
|
|
8
|
+
* Each subclass owns everything a client sees about it, in Elephant's words.
|
|
9
|
+
* Everything a tool of any Calypso server shares lives in `McpTool`.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class ElephantTool<Shape extends InputShape = InputShape> extends McpTool<ToolContext, Shape> {
|
|
12
|
+
}
|
|
@@ -1,40 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { McpTool } from "./McpTool.js";
|
|
2
2
|
/**
|
|
3
|
-
* One Elephant tool:
|
|
3
|
+
* One Elephant tool: a tool handed Elephant's context (the Calypso API as the
|
|
4
|
+
* caller, their agents, their knowledge inventory).
|
|
4
5
|
*
|
|
5
|
-
* Each subclass owns everything a client sees about it, in Elephant's words
|
|
6
|
-
*
|
|
7
|
-
* `call` turns failures into tool errors the model can read and act on,
|
|
8
|
-
* instead of protocol errors it cannot.
|
|
6
|
+
* Each subclass owns everything a client sees about it, in Elephant's words.
|
|
7
|
+
* Everything a tool of any Calypso server shares lives in `McpTool`.
|
|
9
8
|
*/
|
|
10
|
-
export class ElephantTool {
|
|
11
|
-
outputSchema;
|
|
12
|
-
/**
|
|
13
|
-
* Top-level inputs that take a file the user attached in ChatGPT, declared
|
|
14
|
-
* in `_meta["openai/fileParams"]`.
|
|
15
|
-
*/
|
|
16
|
-
fileParams;
|
|
17
|
-
async call(args, context) {
|
|
18
|
-
try {
|
|
19
|
-
return ElephantTool.result(await this.run(args, context));
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
23
|
-
const message = ErrorView.of(detail);
|
|
24
|
-
await context.log.event("error", `${this.name} failed.`, { tool: this.name, error: message }, { detail });
|
|
25
|
-
return {
|
|
26
|
-
isError: true,
|
|
27
|
-
content: [{ type: "text", text: `Error: ${this.failure} ${message}` }],
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
static result(output) {
|
|
32
|
-
if ("text" in output) {
|
|
33
|
-
return { content: [{ type: "text", text: output.text }] };
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
content: [{ type: "text", text: JSON.stringify(output.json, null, 2) }],
|
|
37
|
-
...(output.structured ? { structuredContent: output.structured } : {}),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
9
|
+
export class ElephantTool extends McpTool {
|
|
40
10
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
includeArchived: z.ZodOptional<z.ZodBoolean>;
|
|
7
|
+
includeSources: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
};
|
|
9
|
+
/** `elephant-list-buckets`: what Elephant knows about, folder by folder. */
|
|
10
|
+
export declare class ListBucketsTool extends ElephantTool<typeof inputSchema> {
|
|
11
|
+
readonly name = "elephant-list-buckets";
|
|
12
|
+
readonly title = "List buckets";
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly inputSchema: {
|
|
15
|
+
includeArchived: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
includeSources: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
};
|
|
18
|
+
readonly group: ToolGroup;
|
|
19
|
+
readonly annotations: {
|
|
20
|
+
readOnlyHint: boolean;
|
|
21
|
+
destructiveHint: boolean;
|
|
22
|
+
idempotentHint: boolean;
|
|
23
|
+
openWorldHint: boolean;
|
|
24
|
+
};
|
|
25
|
+
protected readonly failure = "Listing the team's buckets failed.";
|
|
26
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, log }: ToolContext): Promise<ToolOutput>;
|
|
27
|
+
/**
|
|
28
|
+
* The bucket with its sources named. A bucket whose sources cannot be read
|
|
29
|
+
* is returned as it was: the names are a help, and a listing that fails
|
|
30
|
+
* because one bucket's names did not load would be worse than ids alone.
|
|
31
|
+
*/
|
|
32
|
+
private static named;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { CallToolResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { ToolGroup } from "../presets/ToolGroup.js";
|
|
4
|
+
import type { ToolLogger } from "./ToolLogger.js";
|
|
5
|
+
export type InputShape = Record<string, z.ZodTypeAny>;
|
|
6
|
+
export type ToolArgs<Shape extends InputShape> = z.objectOutputType<Shape, z.ZodTypeAny>;
|
|
7
|
+
/** What a tool produced: a JSON payload, or text, plus optional structure. */
|
|
8
|
+
export type ToolOutput = {
|
|
9
|
+
readonly json: unknown;
|
|
10
|
+
readonly structured?: Record<string, unknown>;
|
|
11
|
+
} | {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
};
|
|
14
|
+
/** What every tool is handed, whatever else its product adds: a logger. */
|
|
15
|
+
export type ToolRuntime = {
|
|
16
|
+
readonly log: ToolLogger;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* One MCP tool: its public name, wording and inputs, and what it does.
|
|
20
|
+
*
|
|
21
|
+
* Each subclass owns everything a client sees about it, so there is no second
|
|
22
|
+
* layer that renames or rewrites tools on the way out. `call` turns failures
|
|
23
|
+
* into tool errors the model can read and act on, instead of protocol errors
|
|
24
|
+
* it cannot. `Context` is what the product hands its tools per request.
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class McpTool<Context extends ToolRuntime, Shape extends InputShape = InputShape> {
|
|
27
|
+
abstract readonly name: string;
|
|
28
|
+
abstract readonly title: string;
|
|
29
|
+
abstract readonly description: string;
|
|
30
|
+
abstract readonly inputSchema: Shape;
|
|
31
|
+
/** What the tool does, which decides who is offered it. */
|
|
32
|
+
abstract readonly group: ToolGroup;
|
|
33
|
+
/**
|
|
34
|
+
* The three hints a directory review reads are stated outright on every
|
|
35
|
+
* tool, never left to a default: whether it only reads, whether it can
|
|
36
|
+
* destroy anything, and whether it reaches beyond the caller's own
|
|
37
|
+
* knowledge (a public URL, say). The reading tools answer true, false,
|
|
38
|
+
* false.
|
|
39
|
+
*/
|
|
40
|
+
abstract readonly annotations: ToolAnnotations & {
|
|
41
|
+
readOnlyHint: boolean;
|
|
42
|
+
destructiveHint: boolean;
|
|
43
|
+
openWorldHint: boolean;
|
|
44
|
+
};
|
|
45
|
+
readonly outputSchema?: InputShape;
|
|
46
|
+
/**
|
|
47
|
+
* Top-level inputs that take a file the user attached in ChatGPT, declared
|
|
48
|
+
* in `_meta["openai/fileParams"]`.
|
|
49
|
+
*/
|
|
50
|
+
readonly fileParams?: readonly string[];
|
|
51
|
+
/** First words of the error a failed call returns. */
|
|
52
|
+
protected abstract readonly failure: string;
|
|
53
|
+
protected abstract run(args: ToolArgs<Shape>, context: Context): Promise<ToolOutput>;
|
|
54
|
+
call(args: ToolArgs<Shape>, context: Context): Promise<CallToolResult>;
|
|
55
|
+
private static result;
|
|
56
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ErrorView } from "../views/ErrorView.js";
|
|
2
|
+
/**
|
|
3
|
+
* One MCP tool: its public name, wording and inputs, and what it does.
|
|
4
|
+
*
|
|
5
|
+
* Each subclass owns everything a client sees about it, so there is no second
|
|
6
|
+
* layer that renames or rewrites tools on the way out. `call` turns failures
|
|
7
|
+
* into tool errors the model can read and act on, instead of protocol errors
|
|
8
|
+
* it cannot. `Context` is what the product hands its tools per request.
|
|
9
|
+
*/
|
|
10
|
+
export class McpTool {
|
|
11
|
+
outputSchema;
|
|
12
|
+
/**
|
|
13
|
+
* Top-level inputs that take a file the user attached in ChatGPT, declared
|
|
14
|
+
* in `_meta["openai/fileParams"]`.
|
|
15
|
+
*/
|
|
16
|
+
fileParams;
|
|
17
|
+
async call(args, context) {
|
|
18
|
+
try {
|
|
19
|
+
return McpTool.result(await this.run(args, context));
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
23
|
+
const message = ErrorView.of(detail);
|
|
24
|
+
await context.log.event("error", `${this.name} failed.`, { tool: this.name, error: message }, { detail });
|
|
25
|
+
return {
|
|
26
|
+
isError: true,
|
|
27
|
+
content: [{ type: "text", text: `Error: ${this.failure} ${message}` }],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
static result(output) {
|
|
32
|
+
if ("text" in output) {
|
|
33
|
+
return { content: [{ type: "text", text: output.text }] };
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
content: [{ type: "text", text: JSON.stringify(output.json, null, 2) }],
|
|
37
|
+
...(output.structured ? { structuredContent: output.structured } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
sourceIds: z.ZodArray<z.ZodString, "many">;
|
|
7
|
+
fromBucket: z.ZodString;
|
|
8
|
+
toBucket: z.ZodString;
|
|
9
|
+
};
|
|
10
|
+
/** `elephant-move-sources`: the same sources, filed in another bucket. */
|
|
11
|
+
export declare class MoveSourcesTool extends ElephantTool<typeof inputSchema> {
|
|
12
|
+
readonly name = "elephant-move-sources";
|
|
13
|
+
readonly title = "Move sources";
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly inputSchema: {
|
|
16
|
+
sourceIds: z.ZodArray<z.ZodString, "many">;
|
|
17
|
+
fromBucket: z.ZodString;
|
|
18
|
+
toBucket: z.ZodString;
|
|
19
|
+
};
|
|
20
|
+
readonly group: ToolGroup;
|
|
21
|
+
readonly annotations: {
|
|
22
|
+
readOnlyHint: boolean;
|
|
23
|
+
destructiveHint: boolean;
|
|
24
|
+
idempotentHint: boolean;
|
|
25
|
+
openWorldHint: boolean;
|
|
26
|
+
};
|
|
27
|
+
protected readonly failure = "Moving the sources failed.";
|
|
28
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, log }: ToolContext): Promise<ToolOutput>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
fileId: z.ZodString;
|
|
7
|
+
verify: z.ZodOptional<z.ZodBoolean>;
|
|
8
|
+
};
|
|
9
|
+
/** `elephant-open-source`: one source's details and readiness. */
|
|
10
|
+
export declare class OpenSourceTool extends ElephantTool<typeof inputSchema> {
|
|
11
|
+
readonly name = "elephant-open-source";
|
|
12
|
+
readonly title = "Open a source";
|
|
13
|
+
readonly description: string;
|
|
14
|
+
readonly inputSchema: {
|
|
15
|
+
fileId: z.ZodString;
|
|
16
|
+
verify: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
};
|
|
18
|
+
readonly group: ToolGroup;
|
|
19
|
+
readonly annotations: {
|
|
20
|
+
readOnlyHint: boolean;
|
|
21
|
+
destructiveHint: boolean;
|
|
22
|
+
idempotentHint: boolean;
|
|
23
|
+
openWorldHint: boolean;
|
|
24
|
+
};
|
|
25
|
+
protected readonly failure = "Opening the source failed.";
|
|
26
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api }: ToolContext): Promise<ToolOutput>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
bucket: z.ZodString;
|
|
7
|
+
name: z.ZodOptional<z.ZodString>;
|
|
8
|
+
description: z.ZodOptional<z.ZodString>;
|
|
9
|
+
};
|
|
10
|
+
/** `elephant-rename-bucket`: a bucket's name and note, nothing in it. */
|
|
11
|
+
export declare class RenameBucketTool extends ElephantTool<typeof inputSchema> {
|
|
12
|
+
readonly name = "elephant-rename-bucket";
|
|
13
|
+
readonly title = "Rename a bucket";
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly inputSchema: {
|
|
16
|
+
bucket: z.ZodString;
|
|
17
|
+
name: z.ZodOptional<z.ZodString>;
|
|
18
|
+
description: z.ZodOptional<z.ZodString>;
|
|
19
|
+
};
|
|
20
|
+
readonly group: ToolGroup;
|
|
21
|
+
readonly annotations: {
|
|
22
|
+
readOnlyHint: boolean;
|
|
23
|
+
destructiveHint: boolean;
|
|
24
|
+
idempotentHint: boolean;
|
|
25
|
+
openWorldHint: boolean;
|
|
26
|
+
};
|
|
27
|
+
protected readonly failure = "Renaming the bucket failed.";
|
|
28
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, log }: ToolContext): Promise<ToolOutput>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ToolGroup } from "../presets/ToolGroup.js";
|
|
3
|
+
import { ElephantTool, type ToolArgs, type ToolOutput } from "./ElephantTool.js";
|
|
4
|
+
import type { ToolContext } from "./ToolContext.js";
|
|
5
|
+
declare const inputSchema: {
|
|
6
|
+
query: z.ZodString;
|
|
7
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
8
|
+
buckets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
9
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
depth: z.ZodOptional<z.ZodEnum<["fast", "thorough"]>>;
|
|
11
|
+
alsoSearchFor: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
12
|
+
};
|
|
13
|
+
/** `elephant-search`: matching passages and their sources, no answer. */
|
|
14
|
+
export declare class SearchTool extends ElephantTool<typeof inputSchema> {
|
|
15
|
+
readonly name = "elephant-search";
|
|
16
|
+
readonly title = "Search Elephant";
|
|
17
|
+
readonly description: string;
|
|
18
|
+
readonly inputSchema: {
|
|
19
|
+
query: z.ZodString;
|
|
20
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
21
|
+
buckets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
22
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
depth: z.ZodOptional<z.ZodEnum<["fast", "thorough"]>>;
|
|
24
|
+
alsoSearchFor: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
25
|
+
};
|
|
26
|
+
readonly group: ToolGroup;
|
|
27
|
+
readonly annotations: {
|
|
28
|
+
readOnlyHint: boolean;
|
|
29
|
+
destructiveHint: boolean;
|
|
30
|
+
idempotentHint: boolean;
|
|
31
|
+
openWorldHint: boolean;
|
|
32
|
+
};
|
|
33
|
+
protected readonly failure = "Searching Elephant failed.";
|
|
34
|
+
protected run(args: ToolArgs<typeof inputSchema>, { api, inventory, log }: ToolContext): Promise<ToolOutput>;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentCatalog } from "../calypso/AgentCatalog.js";
|
|
2
|
+
import type { CalypsoApi } from "../calypso/CalypsoApi.js";
|
|
3
|
+
import type { KnowledgeInventory } from "../calypso/KnowledgeInventory.js";
|
|
4
|
+
import type { UsageNotices } from "../notices/UsageNotices.js";
|
|
5
|
+
import type { ToolLogger } from "./ToolLogger.js";
|
|
6
|
+
/**
|
|
7
|
+
* Everything a tool needs for one request: the Calypso API as the caller,
|
|
8
|
+
* the caller's agents, what the team has in Elephant, a logger, and the
|
|
9
|
+
* operator notices told after each call.
|
|
10
|
+
*
|
|
11
|
+
* Built per request from the caller's credential, so a tool can never reach
|
|
12
|
+
* another caller's key or data.
|
|
13
|
+
*/
|
|
14
|
+
export type ToolContext = {
|
|
15
|
+
readonly api: CalypsoApi;
|
|
16
|
+
readonly agents: AgentCatalog;
|
|
17
|
+
readonly inventory: KnowledgeInventory;
|
|
18
|
+
readonly log: ToolLogger;
|
|
19
|
+
readonly notices: UsageNotices;
|
|
20
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
export type LogLevel = "debug" | "info" | "notice" | "warning" | "error";
|
|
3
|
+
/**
|
|
4
|
+
* Structured logs for one tool call: sent to the MCP client, and errors to
|
|
5
|
+
* the server's own log with the caller's principal.
|
|
6
|
+
*
|
|
7
|
+
* Callers log identifiers, counts and statuses only. Prompts, file bytes and
|
|
8
|
+
* API keys never reach a log line.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ToolLogger {
|
|
11
|
+
private readonly server;
|
|
12
|
+
private readonly principal;
|
|
13
|
+
constructor(server: McpServer | null, principal: string);
|
|
14
|
+
event(level: LogLevel, message: string, data?: Record<string, unknown>,
|
|
15
|
+
/** Kept in the server's log only: what a client is not shown. */
|
|
16
|
+
serverOnly?: Record<string, unknown>): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { InputShape, McpTool, ToolRuntime } from "./McpTool.js";
|
|
3
|
+
/** How one tool call went, for whoever wants to hear about it. */
|
|
4
|
+
export type ToolCallReport = {
|
|
5
|
+
readonly tool: string;
|
|
6
|
+
/** The caller's own input, as the tool received it. */
|
|
7
|
+
readonly args: unknown;
|
|
8
|
+
readonly outcome: "ok" | "error";
|
|
9
|
+
readonly durationMs: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Publishes a tool on an MCP server exactly as the tool describes itself.
|
|
13
|
+
*
|
|
14
|
+
* The one place a tool's name, wording, schemas, annotations and file inputs
|
|
15
|
+
* are handed to the SDK, so every Calypso server lists its tools the same way.
|
|
16
|
+
* `observe` hears how each call went once it has its result: the tool's own
|
|
17
|
+
* error handling has already turned a failure into an `isError` result, so
|
|
18
|
+
* the outcome is read from that.
|
|
19
|
+
*/
|
|
20
|
+
export declare const ToolRegistrar: {
|
|
21
|
+
register<Context extends ToolRuntime>(server: McpServer, tool: McpTool<Context, InputShape>, context: Context, observe?: (report: ToolCallReport) => void): void;
|
|
22
|
+
};
|