@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.
Files changed (104) hide show
  1. package/README.md +16 -0
  2. package/dist/ElephantMcpServer.d.ts +45 -0
  3. package/dist/ElephantMcpServer.js +14 -13
  4. package/dist/auth/ApiKeyStrategy.d.ts +14 -0
  5. package/dist/auth/AuthChallenge.d.ts +27 -0
  6. package/dist/auth/AuthStrategy.d.ts +14 -0
  7. package/dist/auth/BearerAuthenticator.d.ts +17 -0
  8. package/dist/auth/Credential.d.ts +23 -0
  9. package/dist/auth/GrantScopes.d.ts +16 -0
  10. package/dist/auth/JwtGrantStrategy.d.ts +30 -0
  11. package/dist/auth/JwtGrantStrategy.js +11 -1
  12. package/dist/auth/ProtectedResource.d.ts +21 -0
  13. package/dist/auth/ProtectedResource.js +1 -0
  14. package/dist/auth/TokenCipher.d.ts +13 -0
  15. package/dist/calypso/AgentCatalog.d.ts +41 -0
  16. package/dist/calypso/AgentCatalogLoader.d.ts +12 -0
  17. package/dist/calypso/AgentChoice.d.ts +25 -0
  18. package/dist/calypso/AgentResponses.d.ts +47 -0
  19. package/dist/calypso/AnswerDepth.d.ts +30 -0
  20. package/dist/calypso/AnswerDiagnostics.d.ts +23 -0
  21. package/dist/calypso/AnswerSources.d.ts +36 -0
  22. package/dist/calypso/BatchManifest.d.ts +29 -0
  23. package/dist/calypso/BucketDestination.d.ts +17 -0
  24. package/dist/calypso/BucketEdits.d.ts +41 -0
  25. package/dist/calypso/BucketSources.d.ts +28 -0
  26. package/dist/calypso/CalypsoApi.d.ts +28 -0
  27. package/dist/calypso/CalypsoApiClient.d.ts +29 -0
  28. package/dist/calypso/CalypsoApiConfig.d.ts +15 -0
  29. package/dist/calypso/KnowledgeBatches.d.ts +25 -0
  30. package/dist/calypso/KnowledgeBuckets.d.ts +18 -0
  31. package/dist/calypso/KnowledgeFiles.d.ts +45 -0
  32. package/dist/calypso/KnowledgeInventory.d.ts +36 -0
  33. package/dist/calypso/KnowledgeSearch.d.ts +52 -0
  34. package/dist/calypso/KnowledgeWebsites.d.ts +39 -0
  35. package/dist/calypso/UploadContent.d.ts +22 -0
  36. package/dist/calypso/apiErrors.d.ts +14 -0
  37. package/dist/calypso/bucketList.d.ts +48 -0
  38. package/dist/calypso/coerce.d.ts +14 -0
  39. package/dist/calypso/knowledgeTypes.d.ts +64 -0
  40. package/dist/calypso/polling.d.ts +14 -0
  41. package/dist/calypso/uploadBytes.d.ts +8 -0
  42. package/dist/hatching/HatchingCopy.d.ts +11 -0
  43. package/dist/http/HostedServer.d.ts +8 -0
  44. package/dist/http/HostedServer.js +10 -0
  45. package/dist/http/HttpConfig.d.ts +40 -0
  46. package/dist/http/HttpConfig.js +15 -3
  47. package/dist/http/HttpServer.d.ts +36 -0
  48. package/dist/http/KnowledgeInventoryCache.d.ts +21 -0
  49. package/dist/http/McpEndpoint.d.ts +39 -0
  50. package/dist/http/McpEndpoint.js +11 -56
  51. package/dist/http/ModelCatalogCache.d.ts +20 -0
  52. package/dist/http/ProtectedResourceMetadata.d.ts +19 -0
  53. package/dist/http/ProtectedResourceMetadata.js +1 -1
  54. package/dist/http/RateLimiter.d.ts +25 -0
  55. package/dist/http/StatelessMcpEndpoint.d.ts +40 -0
  56. package/dist/http/StatelessMcpEndpoint.js +69 -0
  57. package/dist/index.d.ts +2 -0
  58. package/dist/kit.d.ts +35 -0
  59. package/dist/kit.js +31 -0
  60. package/dist/notices/PostBudget.d.ts +15 -0
  61. package/dist/notices/PostBudget.js +32 -0
  62. package/dist/notices/SlackUsageNotices.d.ts +22 -0
  63. package/dist/notices/SlackUsageNotices.js +57 -0
  64. package/dist/notices/UsageMessage.d.ts +22 -0
  65. package/dist/notices/UsageMessage.js +245 -0
  66. package/dist/notices/UsageNotices.d.ts +25 -0
  67. package/dist/notices/UsageNotices.js +4 -0
  68. package/dist/presets/PresetInstructions.d.ts +20 -0
  69. package/dist/presets/ToolGroup.d.ts +30 -0
  70. package/dist/presets/ToolGroup.js +4 -0
  71. package/dist/presets/ToolPreset.d.ts +80 -0
  72. package/dist/presets/ToolPreset.js +6 -1
  73. package/dist/presets/ToolPresetRegistry.d.ts +18 -0
  74. package/dist/stdio/LocalPresets.d.ts +3 -0
  75. package/dist/stdio/StdioOptions.d.ts +16 -0
  76. package/dist/stdio.d.ts +2 -0
  77. package/dist/tools/AddFileTool.d.ts +91 -0
  78. package/dist/tools/AddFilesTool.d.ts +110 -0
  79. package/dist/tools/AddWebsiteTool.d.ts +42 -0
  80. package/dist/tools/AskTool.d.ts +57 -0
  81. package/dist/tools/CreateBucketTool.d.ts +44 -0
  82. package/dist/tools/ElephantTool.d.ts +12 -0
  83. package/dist/tools/ElephantTool.js +6 -36
  84. package/dist/tools/ListBucketsTool.d.ts +34 -0
  85. package/dist/tools/McpTool.d.ts +56 -0
  86. package/dist/tools/McpTool.js +40 -0
  87. package/dist/tools/MoveSourcesTool.d.ts +30 -0
  88. package/dist/tools/OpenSourceTool.d.ts +28 -0
  89. package/dist/tools/RenameBucketTool.d.ts +30 -0
  90. package/dist/tools/SearchTool.d.ts +36 -0
  91. package/dist/tools/ToolContext.d.ts +20 -0
  92. package/dist/tools/ToolLogger.d.ts +17 -0
  93. package/dist/tools/ToolRegistrar.d.ts +22 -0
  94. package/dist/tools/ToolRegistrar.js +33 -0
  95. package/dist/tools/schemaParts.d.ts +38 -0
  96. package/dist/views/BatchView.d.ts +35 -0
  97. package/dist/views/BucketView.d.ts +34 -0
  98. package/dist/views/ErrorView.d.ts +6 -0
  99. package/dist/views/MoveView.d.ts +20 -0
  100. package/dist/views/SearchView.d.ts +36 -0
  101. package/dist/views/SourceView.d.ts +47 -0
  102. package/dist/views/WebsiteView.d.ts +20 -0
  103. package/dist/views/viewFields.d.ts +11 -0
  104. package/package.json +9 -1
@@ -0,0 +1,28 @@
1
+ import type { CalypsoApiClient } from "./CalypsoApiClient.js";
2
+ /** One source in a bucket, as a person would name it. */
3
+ export type BucketSource = {
4
+ id: string;
5
+ name: string;
6
+ type: string;
7
+ /** Indexed and answerable. */
8
+ ready: boolean;
9
+ };
10
+ export type BucketSourcePage = {
11
+ sources: BucketSource[];
12
+ /** How many sources the bucket holds in all. */
13
+ total: number;
14
+ hasMore: boolean;
15
+ };
16
+ /** The most sources named per bucket in one listing. */
17
+ export declare const SOURCES_PER_BUCKET = 50;
18
+ /**
19
+ * What is inside a bucket (`GET /buckets/{id}/sources`): the names behind the
20
+ * ids a bucket listing carries, so a file can be called by its name before
21
+ * any answer has cited it.
22
+ */
23
+ export declare class BucketSources {
24
+ private readonly api;
25
+ constructor(api: CalypsoApiClient);
26
+ firstPage(bucketId: string): Promise<BucketSourcePage>;
27
+ private static source;
28
+ }
@@ -0,0 +1,28 @@
1
+ import { AgentResponses } from "./AgentResponses.js";
2
+ import { BucketEdits } from "./BucketEdits.js";
3
+ import { BucketSources } from "./BucketSources.js";
4
+ import type { CalypsoApiConfig } from "./CalypsoApiConfig.js";
5
+ import { KnowledgeBatches } from "./KnowledgeBatches.js";
6
+ import { KnowledgeBuckets } from "./KnowledgeBuckets.js";
7
+ import { KnowledgeFiles } from "./KnowledgeFiles.js";
8
+ import { KnowledgeSearch } from "./KnowledgeSearch.js";
9
+ import { KnowledgeWebsites } from "./KnowledgeWebsites.js";
10
+ /**
11
+ * The Calypso API as one caller sees it, grouped by resource.
12
+ *
13
+ * Tools take this instead of a key and a base URL so that none of them can
14
+ * build a request by hand: everything a tool does to Calypso is a named
15
+ * operation on one of these resources.
16
+ */
17
+ export declare class CalypsoApi {
18
+ readonly agent: AgentResponses;
19
+ readonly batches: KnowledgeBatches;
20
+ readonly buckets: KnowledgeBuckets;
21
+ readonly bucketEdits: BucketEdits;
22
+ readonly bucketSources: BucketSources;
23
+ readonly files: KnowledgeFiles;
24
+ readonly search: KnowledgeSearch;
25
+ readonly websites: KnowledgeWebsites;
26
+ /** `userAgent` identifies this server on agent calls. */
27
+ constructor(config: CalypsoApiConfig, userAgent: string);
28
+ }
@@ -0,0 +1,29 @@
1
+ import { type CalypsoApiConfig } from "./CalypsoApiConfig.js";
2
+ export type CalypsoRequest = {
3
+ readonly method: "GET" | "POST" | "PATCH";
4
+ /** Sent as JSON when present. */
5
+ readonly body?: unknown;
6
+ /** Extra headers, e.g. `Idempotency-Key`. */
7
+ readonly headers?: Readonly<Record<string, string>>;
8
+ readonly signal?: AbortSignal;
9
+ };
10
+ /**
11
+ * Authenticated JSON transport to the Calypso API for one caller.
12
+ *
13
+ * Every Calypso call goes through `request`, so the bearer header, the URL
14
+ * rule and the error wording exist once instead of once per resource.
15
+ */
16
+ export declare class CalypsoApiClient {
17
+ readonly config: CalypsoApiConfig;
18
+ constructor(config: CalypsoApiConfig);
19
+ /** Absolute URL for a path under the API base, e.g. `/knowledge/buckets`. */
20
+ url(relativePath: string): string;
21
+ /** Performs the call and returns the parsed body; throws on a non-2xx. */
22
+ request<T>(relativePath: string, request: CalypsoRequest): Promise<T>;
23
+ private headersFor;
24
+ }
25
+ /** A non-2xx answer from the Calypso API, with its status kept for callers that branch on it. */
26
+ export declare class CalypsoApiError extends Error {
27
+ readonly status: number;
28
+ constructor(status: number, message: string);
29
+ }
@@ -0,0 +1,15 @@
1
+ export declare const DEFAULT_CALYPSO_API_BASE_URL = "https://api.calypso.so/v1";
2
+ /**
3
+ * What it takes to call the Calypso API on behalf of one caller.
4
+ *
5
+ * Built per request from the caller's credential: the server holds no key of
6
+ * its own, so two requests never share one of these unless they share a key.
7
+ */
8
+ export type CalypsoApiConfig = {
9
+ /** The caller's Calypso API key. */
10
+ readonly apiKey?: string;
11
+ /** Calypso API base URL, ending in /v1. */
12
+ readonly apiBaseUrl: string;
13
+ };
14
+ /** The caller's key, or a clear failure when a request carried none. */
15
+ export declare function requireApiKey(config: CalypsoApiConfig): string;
@@ -0,0 +1,25 @@
1
+ import { type UploadKnowledgeFilesBatchParams } from "./BatchManifest.js";
2
+ import type { CalypsoApiClient } from "./CalypsoApiClient.js";
3
+ import type { KnowledgeBatchObject } from "./knowledgeTypes.js";
4
+ /**
5
+ * Several files added to the team's Calypso knowledge in one request.
6
+ *
7
+ * A batch is its own resource with its own status, so a caller can add a
8
+ * hundred files and follow one id instead of a hundred.
9
+ */
10
+ export declare class KnowledgeBatches {
11
+ private readonly api;
12
+ constructor(api: CalypsoApiClient);
13
+ upload(params: UploadKnowledgeFilesBatchParams): Promise<KnowledgeBatchObject>;
14
+ /** The batch with its items. */
15
+ get(batchId: string): Promise<KnowledgeBatchObject>;
16
+ /**
17
+ * Polls until the batch stops changing. Running out of time is reported in
18
+ * the result rather than thrown: the batch was accepted and will finish, so
19
+ * the caller needs its id and progress, not an error.
20
+ */
21
+ waitUntilReady(batchId: string): Promise<KnowledgeBatchObject>;
22
+ private openSessions;
23
+ /** Items the API rejected have no session and are skipped. */
24
+ private sendBytes;
25
+ }
@@ -0,0 +1,18 @@
1
+ import { type KnowledgeBucketList } from "./bucketList.js";
2
+ import type { CalypsoApiClient } from "./CalypsoApiClient.js";
3
+ export type CreateKnowledgeBucketInput = {
4
+ name: string;
5
+ slug?: string;
6
+ description?: string;
7
+ idempotencyKey?: string;
8
+ };
9
+ /** The team's knowledge buckets: the folders its sources are kept in. */
10
+ export declare class KnowledgeBuckets {
11
+ private readonly api;
12
+ constructor(api: CalypsoApiClient);
13
+ list(options?: {
14
+ includeArchived?: boolean;
15
+ }): Promise<KnowledgeBucketList>;
16
+ /** Creates an empty bucket; a slug already in use is refused by the API. */
17
+ create(input: CreateKnowledgeBucketInput): Promise<Record<string, unknown>>;
18
+ }
@@ -0,0 +1,45 @@
1
+ import { type BucketDestination } from "./BucketDestination.js";
2
+ import type { CalypsoApiClient } from "./CalypsoApiClient.js";
3
+ import type { KnowledgeFileObject, KnowledgeUploadResult } from "./knowledgeTypes.js";
4
+ export type UploadKnowledgeFileParams = BucketDestination & {
5
+ filename?: string;
6
+ mimeType?: string;
7
+ /** The file's bytes, inline. Exactly one of this and `sourceUrl`. */
8
+ contentBase64?: string;
9
+ /** Public link Calypso fetches itself. */
10
+ sourceUrl?: string;
11
+ title?: string;
12
+ tags?: string[];
13
+ metadata?: Record<string, unknown>;
14
+ idempotencyKey?: string;
15
+ waitForIndexing?: boolean;
16
+ };
17
+ /**
18
+ * Single files in the team's Calypso knowledge: look one up, add one, and
19
+ * wait for one to become answerable.
20
+ */
21
+ export declare class KnowledgeFiles {
22
+ private readonly api;
23
+ constructor(api: CalypsoApiClient);
24
+ /** `verify` also asks the index itself, which is slower but authoritative. */
25
+ get(fileId: string, options?: {
26
+ verify?: boolean;
27
+ }): Promise<KnowledgeFileObject>;
28
+ /** Adds one file from inline bytes or from a public link. */
29
+ upload(params: UploadKnowledgeFileParams): Promise<KnowledgeUploadResult>;
30
+ /**
31
+ * Has Calypso fetch a public file itself (`POST /knowledge/files/import-url`).
32
+ *
33
+ * The bytes never pass through this server, which is why a link is the
34
+ * preferred source for anything already online.
35
+ */
36
+ importFromUrl(params: UploadKnowledgeFileParams & {
37
+ sourceUrl: string;
38
+ }): Promise<KnowledgeUploadResult>;
39
+ /** Polls until the file is indexed; throws if indexing fails or stalls. */
40
+ waitUntilIndexed(fileId: string, taskId?: string | null): Promise<KnowledgeUploadResult>;
41
+ /** Session, bytes, finalize: the three steps of a direct upload. */
42
+ private uploadBytes;
43
+ private read;
44
+ private getTask;
45
+ }
@@ -0,0 +1,36 @@
1
+ import type { KnowledgeBucketList } from "./bucketList.js";
2
+ import type { CalypsoApiConfig } from "./CalypsoApiConfig.js";
3
+ /**
4
+ * What the team has in Elephant right now, in the few numbers the hatching
5
+ * copy and the empty-team short-circuit need. Derived from the bucket list
6
+ * on every read; the server keeps no state of its own about a team.
7
+ */
8
+ export type KnowledgeInventorySummary = {
9
+ readonly bucketCount: number;
10
+ /** Files across active buckets, by the most specific count the API gives. */
11
+ readonly readyFileCount: number;
12
+ /** Active bucket names, in the API's order, for example questions. */
13
+ readonly bucketNames: readonly string[];
14
+ /** No active bucket, or none with a file: nothing to answer from. */
15
+ readonly isEmpty: boolean;
16
+ };
17
+ declare const EMPTY_SUMMARY: KnowledgeInventorySummary;
18
+ /** Pure: the summary of one bucket list. */
19
+ export declare function summarizeKnowledge(list: KnowledgeBucketList): KnowledgeInventorySummary;
20
+ /** Loads the summary for one caller; rejects when the API cannot be reached. */
21
+ export declare function loadKnowledgeInventory(config: CalypsoApiConfig): Promise<KnowledgeInventorySummary>;
22
+ /**
23
+ * The inventory as a tool sees it in one request: seeded from the endpoint's
24
+ * cache, re-read once when the seed says "empty" so a source added seconds
25
+ * ago is not missed, and never read at all when there is no seed (the local
26
+ * stdio server and the unit tests keep today's behaviour).
27
+ */
28
+ export declare class KnowledgeInventory {
29
+ private readonly seed;
30
+ private readonly reload;
31
+ private fresh;
32
+ constructor(seed: KnowledgeInventorySummary | null, reload: () => Promise<KnowledgeBucketList>);
33
+ /** The seed when it has knowledge; a fresh read when it is empty; null without a seed. */
34
+ current(): Promise<KnowledgeInventorySummary | null>;
35
+ }
36
+ export { EMPTY_SUMMARY as EMPTY_KNOWLEDGE_INVENTORY };
@@ -0,0 +1,52 @@
1
+ import { type SearchDepthName } from "./AnswerDepth.js";
2
+ import type { CalypsoApiClient } from "./CalypsoApiClient.js";
3
+ export type KnowledgeSearchResult = {
4
+ source_index: number;
5
+ type: string;
6
+ title?: string | null;
7
+ /** The whole matching passage, as the document has it. */
8
+ text?: string | null;
9
+ /** The line in the passage that matched most closely, when one stood out. */
10
+ quote?: string | null;
11
+ file_id?: string | null;
12
+ filename?: string | null;
13
+ url?: string | null;
14
+ attributes: Record<string, unknown>;
15
+ };
16
+ export type KnowledgeSearchResponse = {
17
+ object: string;
18
+ query: string;
19
+ agent?: string | null;
20
+ strategy: string;
21
+ /** The depth the search ran at, as the API names it. */
22
+ depth?: string;
23
+ results: KnowledgeSearchResult[];
24
+ usage: {
25
+ input_tokens: number;
26
+ output_tokens: number;
27
+ total_tokens: number;
28
+ };
29
+ request_id?: string;
30
+ };
31
+ export type SearchKnowledgeOptions = {
32
+ query: string;
33
+ /** Search what this agent can see. Not together with `buckets`. */
34
+ agent?: string;
35
+ /** Bucket ids or slugs to search directly. */
36
+ buckets?: string[];
37
+ maxResults?: number;
38
+ depth?: SearchDepthName;
39
+ /** Other phrasings of the same question, searched alongside it. */
40
+ alsoSearchFor?: string[];
41
+ };
42
+ /** The API searches at most this many extra phrasings. */
43
+ export declare const MAX_EXTRA_QUERIES = 2;
44
+ /**
45
+ * Retrieval without an answer (`POST /search`): the passages and sources an
46
+ * agent would cite, for callers that want the evidence itself.
47
+ */
48
+ export declare class KnowledgeSearch {
49
+ private readonly api;
50
+ constructor(api: CalypsoApiClient);
51
+ search(options: SearchKnowledgeOptions): Promise<KnowledgeSearchResponse>;
52
+ }
@@ -0,0 +1,39 @@
1
+ import type { CalypsoApiClient } from "./CalypsoApiClient.js";
2
+ export type AddKnowledgeWebsiteInput = {
3
+ url: string;
4
+ title?: string;
5
+ tagsHint?: string;
6
+ preferredLanguage?: string;
7
+ bucketIds?: string[];
8
+ bucketSlugs?: string[];
9
+ bucket?: string;
10
+ createMissingBuckets?: boolean;
11
+ idempotencyKey?: string;
12
+ };
13
+ export type KnowledgeWebsiteObject = {
14
+ object?: string;
15
+ knowledge_id?: string;
16
+ team_id?: string;
17
+ title?: string;
18
+ tags?: string[];
19
+ url?: string;
20
+ summary?: string;
21
+ ingestion_status?: string;
22
+ bucket_assignment?: Record<string, unknown>;
23
+ request_id?: string;
24
+ [key: string]: unknown;
25
+ };
26
+ /** Web pages kept as knowledge in the team's buckets. */
27
+ export declare class KnowledgeWebsites {
28
+ private readonly api;
29
+ constructor(api: CalypsoApiClient);
30
+ /**
31
+ * Adds a page in one call (`POST /knowledge/websites`): Calypso reads it,
32
+ * writes its title, summary and tags, and files it in the given buckets.
33
+ *
34
+ * The normalized URL identifies the website within a team, so adding the
35
+ * same page twice is a conflict unless the same `Idempotency-Key` is sent,
36
+ * in which case the existing website is returned.
37
+ */
38
+ add(input: AddKnowledgeWebsiteInput): Promise<KnowledgeWebsiteObject>;
39
+ }
@@ -0,0 +1,22 @@
1
+ export declare const DEFAULT_MIME_TYPE = "application/octet-stream";
2
+ /** A file as a caller hands it over: its bytes inline, as base64. */
3
+ export type UploadContentSource = {
4
+ filename?: string;
5
+ mimeType?: string;
6
+ contentBase64?: string;
7
+ };
8
+ export type UploadContent = {
9
+ bytes: Uint8Array;
10
+ filename: string;
11
+ mimeType: string;
12
+ };
13
+ /** Accepts a `data:…;base64,` URI where plain base64 was expected. */
14
+ export declare function stripDataUriPrefix(value: string): string;
15
+ /**
16
+ * Decodes the bytes a caller sent inline.
17
+ *
18
+ * Inline bytes are the only content this server takes from a caller itself (a
19
+ * public link is fetched by Calypso, not here). It deliberately has no way to
20
+ * name a path: on a hosted server that would read the server's own disk.
21
+ */
22
+ export declare function decodeUploadContent(input: UploadContentSource): UploadContent;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Reads a Calypso API response body without assuming it is JSON.
3
+ *
4
+ * Errors from proxies in front of the API arrive as text or HTML; reading them
5
+ * as text keeps the failure message useful instead of a JSON parse error.
6
+ */
7
+ export declare function readResponseBody(response: Response): Promise<unknown>;
8
+ /**
9
+ * Turns a failed response into the one-line message a tool result carries.
10
+ *
11
+ * The API's typed error (`code: message`) is passed through verbatim because
12
+ * the code is what tells the model whether a retry or a different input helps.
13
+ */
14
+ export declare function formatApiError(status: number, body: unknown): string;
@@ -0,0 +1,48 @@
1
+ export type KnowledgeBucketStoreState = {
2
+ alias?: string | null;
3
+ gemini_store_name?: string | null;
4
+ status?: string;
5
+ file_count?: number;
6
+ indexed_file_count?: number;
7
+ pending_file_count?: number;
8
+ member_count?: number;
9
+ indexed_member_count?: number;
10
+ pending_member_count?: number;
11
+ last_synced_at?: unknown;
12
+ last_error?: string | null;
13
+ };
14
+ export type KnowledgeBucketDescriptor = {
15
+ id: string;
16
+ teamId?: string;
17
+ slug?: string;
18
+ name?: string;
19
+ description?: string | null;
20
+ status?: string;
21
+ knowledgeIds: string[];
22
+ fileIds: string[];
23
+ fileKnowledgeIds: string[];
24
+ filesCount?: number;
25
+ memberCount?: number;
26
+ rawMemberCount?: number;
27
+ fileCount?: number;
28
+ retrievableFileCount?: number;
29
+ staleMemberCount?: number;
30
+ activeNonFileMemberCount?: number;
31
+ counts: Record<string, number>;
32
+ bucketStore?: KnowledgeBucketStoreState | null;
33
+ };
34
+ export type KnowledgeBucketList = {
35
+ team_id: string;
36
+ buckets: KnowledgeBucketDescriptor[];
37
+ request_id?: string;
38
+ };
39
+ /**
40
+ * Reads a bucket listing into a stable shape.
41
+ *
42
+ * The listing is what a model reads to choose buckets and file ids, so it is
43
+ * normalized rather than passed through: blank and duplicate entries are
44
+ * dropped, and the two names the API has used for a bucket's files
45
+ * (`fileIds`, formerly `fileKnowledgeIds`) are both filled from whichever is
46
+ * present.
47
+ */
48
+ export declare function normalizeKnowledgeBucketList(value: unknown): KnowledgeBucketList;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Small readers for untyped API payloads.
3
+ *
4
+ * The Calypso API grows fields over time and older deployments omit some, so
5
+ * responses are read defensively rather than trusted to match a type.
6
+ */
7
+ /** A non-empty trimmed string, or undefined for anything else. */
8
+ export declare function trimmedString(value: unknown): string | undefined;
9
+ export declare function numberOrUndefined(value: unknown): number | undefined;
10
+ /** Trimmed, non-empty, de-duplicated strings in first-seen order. */
11
+ export declare function uniqueStrings(value: unknown): string[];
12
+ /** Trimmed non-empty strings, or undefined when none remain. */
13
+ export declare function compactStrings(values?: string[]): string[] | undefined;
14
+ export declare function asRecord(value: unknown): Record<string, unknown> | null;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Shapes of the Calypso knowledge API's answers.
3
+ *
4
+ * Every type is open (`[key: string]: unknown`) because the API adds fields
5
+ * over time. None of these is ever handed to a client as it is: each tool
6
+ * answers with a view (`src/views`) that names the fields it returns.
7
+ */
8
+ export type KnowledgeTaskObject = {
9
+ id: string;
10
+ type?: string;
11
+ status?: string;
12
+ [key: string]: unknown;
13
+ };
14
+ export type KnowledgeFileObject = {
15
+ id: string;
16
+ object?: string;
17
+ status?: string;
18
+ title?: string;
19
+ filename?: string;
20
+ content_type?: string;
21
+ size_bytes?: number;
22
+ sha256?: string;
23
+ task?: KnowledgeTaskObject;
24
+ source?: Record<string, unknown>;
25
+ created_at?: string;
26
+ updated_at?: string;
27
+ request_id?: string;
28
+ [key: string]: unknown;
29
+ };
30
+ /** A file as an upload leaves it, with the indexing task when there is one. */
31
+ export type KnowledgeUploadResult = {
32
+ file: KnowledgeFileObject;
33
+ task?: KnowledgeTaskObject | null;
34
+ };
35
+ export type KnowledgeBatchItemObject = {
36
+ client_file_id?: string;
37
+ clientFileId?: string;
38
+ status?: string;
39
+ file?: KnowledgeFileObject;
40
+ knowledgeId?: string;
41
+ taskId?: string;
42
+ canonicalStatus?: string;
43
+ bucketSyncStatus?: string;
44
+ bucketSync?: Record<string, unknown>;
45
+ error?: Record<string, unknown>;
46
+ [key: string]: unknown;
47
+ };
48
+ export type KnowledgeBatchObject = {
49
+ id: string;
50
+ object?: "knowledge_batch";
51
+ status?: string;
52
+ message?: string;
53
+ total?: number;
54
+ accepted?: number;
55
+ rejected?: number;
56
+ queued?: number;
57
+ indexing?: number;
58
+ active?: number;
59
+ partialFailedCount?: number;
60
+ failed?: number;
61
+ items?: KnowledgeBatchItemObject[];
62
+ request_id?: string;
63
+ [key: string]: unknown;
64
+ };
@@ -0,0 +1,14 @@
1
+ export type PollOutcome<T> = {
2
+ /** The last state read. */
3
+ readonly last: T;
4
+ /** False when attempts ran out before `isSettled` said yes. */
5
+ readonly settled: boolean;
6
+ };
7
+ /**
8
+ * Reads a state repeatedly, backing off, until it settles or attempts run out.
9
+ *
10
+ * Indexing takes seconds to minutes; the budget here (about two and a half
11
+ * minutes) is what a tool call can reasonably hold open. Running out is an
12
+ * outcome, not an exception, because callers describe it differently.
13
+ */
14
+ export declare function pollUntilSettled<T>(read: () => Promise<T>, isSettled: (state: T) => boolean): Promise<PollOutcome<T>>;
@@ -0,0 +1,8 @@
1
+ import { type UploadContent } from "./UploadContent.js";
2
+ /**
3
+ * Sends a file's bytes to the storage URL an upload session handed out.
4
+ *
5
+ * The URL is pre-signed storage, not the Calypso API, so it gets no bearer
6
+ * header: the caller's key must never travel to another host.
7
+ */
8
+ export declare function putUploadBytes(uploadUrl: string, content: UploadContent): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import type { KnowledgeInventorySummary } from "../calypso/KnowledgeInventory.js";
2
+ /** Where a person adds sources; the one link the hatch ever shows. */
3
+ export declare const KNOWLEDGE_URL = "https://elephant.calypso.so/buckets";
4
+ /** `initialize.instructions`: the preset's text, or the empty-team variant. */
5
+ export declare function hatchingInstructions(base: string, summary: KnowledgeInventorySummary | null): string;
6
+ /** The `elephant-get-started` card: the whole setup for an empty team, a tour otherwise. */
7
+ export declare function hatchingCard(summary: KnowledgeInventorySummary | null): string;
8
+ /** What an empty team hears when it asks or searches: the hatch, not an apology. */
9
+ export declare function emptyKnowledgeAnswer(): string;
10
+ /** Three example questions, drawn from the team's bucket names when it has them. */
11
+ export declare function hatchingExamples(summary: KnowledgeInventorySummary): string[];
@@ -0,0 +1,8 @@
1
+ import type { PackageInfo } from "../ElephantMcpServer.js";
2
+ import type { HttpConfig } from "./HttpConfig.js";
3
+ import { HttpServer } from "./HttpServer.js";
4
+ /**
5
+ * Composition root for the hosted server: wires config into strategies,
6
+ * endpoints and the HTTP router. The only place that knows every piece.
7
+ */
8
+ export declare function composeHostedServer(config: HttpConfig, packageInfo: PackageInfo): HttpServer;
@@ -3,6 +3,8 @@ import { ApiKeyStrategy } from "../auth/ApiKeyStrategy.js";
3
3
  import { BearerAuthenticator } from "../auth/BearerAuthenticator.js";
4
4
  import { JwtGrantStrategy } from "../auth/JwtGrantStrategy.js";
5
5
  import { TokenCipher } from "../auth/TokenCipher.js";
6
+ import { SlackUsageNotices } from "../notices/SlackUsageNotices.js";
7
+ import { NoUsageNotices } from "../notices/UsageNotices.js";
6
8
  import { ToolPresetRegistry } from "../presets/ToolPresetRegistry.js";
7
9
  import { HttpServer } from "./HttpServer.js";
8
10
  import { KnowledgeInventoryCache } from "./KnowledgeInventoryCache.js";
@@ -31,6 +33,13 @@ export function composeHostedServer(config, packageInfo) {
31
33
  const catalogs = new ModelCatalogCache();
32
34
  const inventories = new KnowledgeInventoryCache();
33
35
  const limiter = new RateLimiter(config.requestsPerMinute);
36
+ // One channel hears every noticed tool call; without a webhook nobody does.
37
+ const notices = config.slackWebhookUrl
38
+ ? new SlackUsageNotices(config.slackWebhookUrl, {
39
+ version: packageInfo.version,
40
+ publicBaseUrl: config.publicBaseUrl,
41
+ })
42
+ : new NoUsageNotices();
34
43
  const endpoints = ToolPresetRegistry.all().map((preset) => new McpEndpoint({
35
44
  preset,
36
45
  authenticator,
@@ -39,6 +48,7 @@ export function composeHostedServer(config, packageInfo) {
39
48
  limiter,
40
49
  apiBaseUrl: config.apiBaseUrl,
41
50
  packageInfo,
51
+ notices,
42
52
  }));
43
53
  return new HttpServer({
44
54
  endpoints,
@@ -0,0 +1,40 @@
1
+ export declare const DEFAULT_PUBLIC_BASE_URL = "https://mcp.calypso.so";
2
+ export declare const DEFAULT_OAUTH_ISSUER = "https://login.calypso.so";
3
+ /**
4
+ * Settings for the Elephant server, read once at startup.
5
+ *
6
+ * | Env | Meaning |
7
+ * |----------------------------|------------------------------------------------------|
8
+ * | PORT | listen port (Render sets it) |
9
+ * | ELEPHANT_PUBLIC_BASE_URL | public origin; `aud` = this + preset path |
10
+ * | CALYPSO_OAUTH_ISSUER | authorization server issuer |
11
+ * | ELEPHANT_JWKS_URL | override for the issuer's JWKS URL |
12
+ * | ELEPHANT_TOKEN_ENC_KEY | 32-byte base64 key for the `ek` claim; unset = OAuth off, API keys only |
13
+ * | CALYPSO_API_BASE_URL | Calypso API base URL (…/v1) |
14
+ * | ELEPHANT_REQUESTS_PER_MINUTE | per-caller request budget (default 120) |
15
+ * | ELEPHANT_OPENAI_CHALLENGE_TOKEN | OpenAI plugin portal domain-verification token (public) |
16
+ * | ELEPHANT_SLACK_WEBHOOK_URL | Slack incoming webhook told about each noticed tool call; unset = no notices |
17
+ */
18
+ export declare class HttpConfig {
19
+ readonly port: number;
20
+ readonly publicBaseUrl: string;
21
+ readonly issuer: string;
22
+ readonly jwksUrl: string;
23
+ readonly tokenEncKey: string | undefined;
24
+ readonly apiBaseUrl: string;
25
+ readonly maxBodyBytes: number;
26
+ readonly requestsPerMinute: number;
27
+ readonly openaiChallengeToken: string | undefined;
28
+ readonly slackWebhookUrl: string | undefined;
29
+ private constructor();
30
+ /**
31
+ * `prefix` names the product in the env keys (`ELEPHANT_PUBLIC_BASE_URL`,
32
+ * `WHATSAPP_PUBLIC_BASE_URL`, …) and `publicBaseUrl` is where that product
33
+ * is served when the env does not say. Both default to Elephant's.
34
+ */
35
+ static fromEnv(env: NodeJS.ProcessEnv, product?: {
36
+ prefix?: string;
37
+ publicBaseUrl?: string;
38
+ }): HttpConfig;
39
+ get oauthEnabled(): boolean;
40
+ }
@@ -17,6 +17,7 @@ const DEFAULT_REQUESTS_PER_MINUTE = 120;
17
17
  * | CALYPSO_API_BASE_URL | Calypso API base URL (…/v1) |
18
18
  * | ELEPHANT_REQUESTS_PER_MINUTE | per-caller request budget (default 120) |
19
19
  * | ELEPHANT_OPENAI_CHALLENGE_TOKEN | OpenAI plugin portal domain-verification token (public) |
20
+ * | ELEPHANT_SLACK_WEBHOOK_URL | Slack incoming webhook told about each noticed tool call; unset = no notices |
20
21
  */
21
22
  export class HttpConfig {
22
23
  port;
@@ -28,7 +29,8 @@ export class HttpConfig {
28
29
  maxBodyBytes;
29
30
  requestsPerMinute;
30
31
  openaiChallengeToken;
31
- constructor(port, publicBaseUrl, issuer, jwksUrl, tokenEncKey, apiBaseUrl, maxBodyBytes, requestsPerMinute, openaiChallengeToken) {
32
+ slackWebhookUrl;
33
+ constructor(port, publicBaseUrl, issuer, jwksUrl, tokenEncKey, apiBaseUrl, maxBodyBytes, requestsPerMinute, openaiChallengeToken, slackWebhookUrl) {
32
34
  this.port = port;
33
35
  this.publicBaseUrl = publicBaseUrl;
34
36
  this.issuer = issuer;
@@ -38,14 +40,24 @@ export class HttpConfig {
38
40
  this.maxBodyBytes = maxBodyBytes;
39
41
  this.requestsPerMinute = requestsPerMinute;
40
42
  this.openaiChallengeToken = openaiChallengeToken;
43
+ this.slackWebhookUrl = slackWebhookUrl;
41
44
  }
42
- static fromEnv(env) {
45
+ /**
46
+ * `prefix` names the product in the env keys (`ELEPHANT_PUBLIC_BASE_URL`,
47
+ * `WHATSAPP_PUBLIC_BASE_URL`, …) and `publicBaseUrl` is where that product
48
+ * is served when the env does not say. Both default to Elephant's.
49
+ */
50
+ static fromEnv(env, product = {}) {
51
+ const prefix = product.prefix ?? "ELEPHANT";
43
52
  const issuer = stripSlash(env.CALYPSO_OAUTH_ISSUER) ?? DEFAULT_OAUTH_ISSUER;
44
53
  const apiBaseUrl = stripSlash(env.CALYPSO_API_BASE_URL) ?? DEFAULT_CALYPSO_API_BASE_URL;
45
54
  if (!apiBaseUrl.endsWith("/v1")) {
46
55
  throw new Error("CALYPSO_API_BASE_URL must end in /v1.");
47
56
  }
48
- return new HttpConfig(parsePort(env.PORT), stripSlash(env.ELEPHANT_PUBLIC_BASE_URL) ?? DEFAULT_PUBLIC_BASE_URL, issuer, stripSlash(env.ELEPHANT_JWKS_URL) ?? `${issuer}/.well-known/jwks.json`, env.ELEPHANT_TOKEN_ENC_KEY?.trim() || undefined, apiBaseUrl, DEFAULT_MAX_BODY_BYTES, parsePositive(env.ELEPHANT_REQUESTS_PER_MINUTE, DEFAULT_REQUESTS_PER_MINUTE, "ELEPHANT_REQUESTS_PER_MINUTE"), env.ELEPHANT_OPENAI_CHALLENGE_TOKEN?.trim() || undefined);
57
+ return new HttpConfig(parsePort(env.PORT), stripSlash(env[`${prefix}_PUBLIC_BASE_URL`]) ??
58
+ product.publicBaseUrl ??
59
+ DEFAULT_PUBLIC_BASE_URL, issuer, stripSlash(env[`${prefix}_JWKS_URL`]) ??
60
+ `${issuer}/.well-known/jwks.json`, env[`${prefix}_TOKEN_ENC_KEY`]?.trim() || undefined, apiBaseUrl, DEFAULT_MAX_BODY_BYTES, parsePositive(env[`${prefix}_REQUESTS_PER_MINUTE`], DEFAULT_REQUESTS_PER_MINUTE, `${prefix}_REQUESTS_PER_MINUTE`), env[`${prefix}_OPENAI_CHALLENGE_TOKEN`]?.trim() || undefined, env[`${prefix}_SLACK_WEBHOOK_URL`]?.trim() || undefined);
49
61
  }
50
62
  get oauthEnabled() {
51
63
  return Boolean(this.tokenEncKey);