@archbee/mcp 2.0.0 → 2.2.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 +119 -6
- package/dist/index.js +87 -193
- package/dist/index.js.map +1 -1
- package/dist/tool-schemas.js +306 -0
- package/dist/tool-schemas.js.map +1 -0
- package/package.json +2 -1
- package/src/index.ts +233 -212
- package/src/tool-schemas.ts +372 -0
package/src/index.ts
CHANGED
|
@@ -2,9 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
4
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
5
|
-
import { type CallToolResult } from '@modelcontextprotocol/sdk/types'
|
|
5
|
+
import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js'
|
|
6
6
|
import axios from 'axios'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
applyTemplateSchema,
|
|
9
|
+
createCategorySchema,
|
|
10
|
+
createContentSnippetSchema,
|
|
11
|
+
createDocSchema,
|
|
12
|
+
createDocSpaceSchema,
|
|
13
|
+
createSpaceGroupSchema,
|
|
14
|
+
createTemplateSchema,
|
|
15
|
+
createVariableSchema,
|
|
16
|
+
deleteCategorySchema,
|
|
17
|
+
deleteContentSnippetSchema,
|
|
18
|
+
deleteDocSchema,
|
|
19
|
+
deleteDocSpaceSchema,
|
|
20
|
+
deleteSpaceGroupSchema,
|
|
21
|
+
deleteVariableSchema,
|
|
22
|
+
getAllDocsSchema,
|
|
23
|
+
getDocSchema,
|
|
24
|
+
listContentSnippetsSchema,
|
|
25
|
+
listTemplatesSchema,
|
|
26
|
+
listVariablesSchema,
|
|
27
|
+
searchQuerySchema,
|
|
28
|
+
searchTitleSchema,
|
|
29
|
+
updateContentSnippetSchema,
|
|
30
|
+
updateDocSchema,
|
|
31
|
+
updateDocSpaceSchema,
|
|
32
|
+
updateVariableSchema,
|
|
33
|
+
} from './tool-schemas'
|
|
8
34
|
|
|
9
35
|
interface McpApiParams {
|
|
10
36
|
tool: string
|
|
@@ -19,8 +45,17 @@ interface McpApiParams {
|
|
|
19
45
|
description?: string
|
|
20
46
|
previewImgURL?: string
|
|
21
47
|
hidden?: boolean
|
|
48
|
+
icon?: string
|
|
22
49
|
recursive?: boolean
|
|
23
50
|
name?: string
|
|
51
|
+
templateId?: string
|
|
52
|
+
snippetId?: string
|
|
53
|
+
variableId?: string
|
|
54
|
+
variableType?: 'variable' | 'glossary'
|
|
55
|
+
variableContent?: string
|
|
56
|
+
spaceTargetMap?: Record<string, string>
|
|
57
|
+
categoryName?: string
|
|
58
|
+
categoryId?: string
|
|
24
59
|
docSpaceGroupId?: string
|
|
25
60
|
isAiEnabled?: boolean
|
|
26
61
|
isReviewSystemEnabled?: boolean
|
|
@@ -30,257 +65,214 @@ interface McpApiParams {
|
|
|
30
65
|
publicAccessControlPart?: Record<string, unknown>
|
|
31
66
|
}
|
|
32
67
|
|
|
33
|
-
|
|
34
|
-
|
|
68
|
+
// A team key is not bound to a space, so the space travels per call instead of
|
|
69
|
+
// being packed into the credential like a space key is.
|
|
70
|
+
const TEAM_API_KEY_PREFIX = 'abteam_'
|
|
71
|
+
|
|
72
|
+
const usesTeamApiKey = (): boolean =>
|
|
73
|
+
(process.env.API_KEY || '').startsWith(TEAM_API_KEY_PREFIX)
|
|
35
74
|
|
|
36
75
|
// Create an MCP server
|
|
37
76
|
const server = new McpServer({
|
|
38
77
|
name: 'Archbee MCP',
|
|
39
|
-
version: '
|
|
78
|
+
version: '2.2.0',
|
|
40
79
|
})
|
|
41
80
|
|
|
42
|
-
server.tool(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
server.tool(
|
|
82
|
+
'get_all_docs',
|
|
83
|
+
'Read every document in the Archbee doc space, with its content, and each document carries the name of the space it belongs to (docSpaceName). Returns the whole space, so prefer search_query or search_title when looking for something specific.',
|
|
84
|
+
getAllDocsSchema,
|
|
85
|
+
async (args) => callMcpApi({ tool: 'get-all-docs', ...args })
|
|
86
|
+
)
|
|
48
87
|
|
|
49
|
-
server.tool(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
})
|
|
88
|
+
server.tool(
|
|
89
|
+
'get_doc',
|
|
90
|
+
'Read one Archbee document by id and return its content as markdown, alongside the id and name of the space it lives in.',
|
|
91
|
+
getDocSchema,
|
|
92
|
+
async (args) => callMcpApi({ tool: 'get-doc', ...args })
|
|
93
|
+
)
|
|
56
94
|
|
|
57
|
-
server.tool(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
})
|
|
95
|
+
server.tool(
|
|
96
|
+
'search_query',
|
|
97
|
+
'Search the Archbee doc space by document content and return the matching documents. This is the tool to use for answering a question from the documentation. An empty query returns every document.',
|
|
98
|
+
searchQuerySchema,
|
|
99
|
+
async (args) => callMcpApi({ tool: 'search-query', ...args })
|
|
100
|
+
)
|
|
64
101
|
|
|
65
|
-
server.tool(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
})
|
|
102
|
+
server.tool(
|
|
103
|
+
'search_title',
|
|
104
|
+
'Search the Archbee doc space by document title. Use this when looking for a page by name; use search_query to search inside document content.',
|
|
105
|
+
searchTitleSchema,
|
|
106
|
+
async (args) => callMcpApi({ tool: 'search-title', ...args })
|
|
107
|
+
)
|
|
72
108
|
|
|
73
|
-
// Write tools.
|
|
74
|
-
//
|
|
109
|
+
// Write tools. With a space key the target space comes from SPACE_ID; with a
|
|
110
|
+
// team key it comes from the docSpaceId argument, which the team-level tools
|
|
111
|
+
// below do not take because they act on the team, not on a space.
|
|
75
112
|
|
|
76
113
|
server.tool(
|
|
77
114
|
'create_doc',
|
|
78
115
|
'Create a new document in the Archbee doc space from Markdown or MDX content.',
|
|
79
|
-
|
|
80
|
-
content: z
|
|
81
|
-
.string()
|
|
82
|
-
.describe(
|
|
83
|
-
'Body of the document to create, as Markdown or MDX text. JSON document content is not accepted.'
|
|
84
|
-
),
|
|
85
|
-
format: z
|
|
86
|
-
.enum(['markdown', 'mdx'])
|
|
87
|
-
.optional()
|
|
88
|
-
.describe(MDX_FORMAT_DESCRIPTION),
|
|
89
|
-
title: z.string().optional().describe('Title of the document.'),
|
|
90
|
-
parentDocId: z
|
|
91
|
-
.string()
|
|
92
|
-
.optional()
|
|
93
|
-
.describe('ID of the parent document to nest this document under.'),
|
|
94
|
-
slug: z.string().optional().describe('URL slug for the document.'),
|
|
95
|
-
description: z
|
|
96
|
-
.string()
|
|
97
|
-
.optional()
|
|
98
|
-
.describe('Short description / summary of the document.'),
|
|
99
|
-
previewImgURL: z
|
|
100
|
-
.string()
|
|
101
|
-
.optional()
|
|
102
|
-
.describe('URL of the preview / social image for the document.'),
|
|
103
|
-
hidden: z
|
|
104
|
-
.boolean()
|
|
105
|
-
.optional()
|
|
106
|
-
.describe('When true, the document is hidden from navigation.'),
|
|
107
|
-
},
|
|
116
|
+
createDocSchema,
|
|
108
117
|
async (args) => callWriteApi({ tool: 'create-doc', ...args })
|
|
109
118
|
)
|
|
110
119
|
|
|
111
120
|
server.tool(
|
|
112
121
|
'update_doc',
|
|
113
122
|
'Update an existing Archbee document. Only the provided fields are changed.',
|
|
114
|
-
|
|
115
|
-
docId: z.string().describe('ID of the document to update.'),
|
|
116
|
-
content: z
|
|
117
|
-
.string()
|
|
118
|
-
.optional()
|
|
119
|
-
.describe(
|
|
120
|
-
'New body for the document, as Markdown or MDX text. JSON document content is not accepted.'
|
|
121
|
-
),
|
|
122
|
-
format: z
|
|
123
|
-
.enum(['markdown', 'mdx'])
|
|
124
|
-
.optional()
|
|
125
|
-
.describe(MDX_FORMAT_DESCRIPTION),
|
|
126
|
-
title: z.string().optional().describe('New title of the document.'),
|
|
127
|
-
parentDocId: z
|
|
128
|
-
.string()
|
|
129
|
-
.optional()
|
|
130
|
-
.describe('ID of the parent document to move this document under.'),
|
|
131
|
-
slug: z.string().optional().describe('New URL slug for the document.'),
|
|
132
|
-
description: z
|
|
133
|
-
.string()
|
|
134
|
-
.optional()
|
|
135
|
-
.describe('New short description / summary of the document.'),
|
|
136
|
-
previewImgURL: z
|
|
137
|
-
.string()
|
|
138
|
-
.optional()
|
|
139
|
-
.describe('New preview / social image URL for the document.'),
|
|
140
|
-
hidden: z
|
|
141
|
-
.boolean()
|
|
142
|
-
.optional()
|
|
143
|
-
.describe('When true, the document is hidden from navigation.'),
|
|
144
|
-
},
|
|
123
|
+
updateDocSchema,
|
|
145
124
|
async (args) => callWriteApi({ tool: 'update-doc', ...args })
|
|
146
125
|
)
|
|
147
126
|
|
|
148
127
|
server.tool(
|
|
149
128
|
'delete_doc',
|
|
150
129
|
'Permanently delete an Archbee document. This is destructive and cannot be undone: the document is removed together with every file and image uploaded to it, and any documents nested underneath it are deleted as well. Ask the user to confirm before calling this tool.',
|
|
151
|
-
|
|
152
|
-
docId: z.string().describe('ID of the document to delete.'),
|
|
153
|
-
recursive: z
|
|
154
|
-
.boolean()
|
|
155
|
-
.optional()
|
|
156
|
-
.describe(
|
|
157
|
-
'Required (set to true) to delete a document that has nested child documents, which deletes those children too. When the document has children and this is not set, the call is rejected and the response lists the child documents that would be affected.'
|
|
158
|
-
),
|
|
159
|
-
},
|
|
130
|
+
deleteDocSchema,
|
|
160
131
|
async (args) => callWriteApi({ tool: 'delete-doc', ...args })
|
|
161
132
|
)
|
|
162
133
|
|
|
163
134
|
server.tool(
|
|
164
135
|
'create_doc_space',
|
|
165
136
|
'Create a new doc space (documentation space) in the current Archbee team.',
|
|
166
|
-
|
|
167
|
-
name: z.string().describe('Name of the new doc space.'),
|
|
168
|
-
isReviewSystemEnabled: z
|
|
169
|
-
.boolean()
|
|
170
|
-
.optional()
|
|
171
|
-
.describe('Enable the review/approval workflow for the space.'),
|
|
172
|
-
isBranchingSystemEnabled: z
|
|
173
|
-
.boolean()
|
|
174
|
-
.optional()
|
|
175
|
-
.describe('Enable the branching (git-style) workflow for the space.'),
|
|
176
|
-
docSpaceGroupId: z
|
|
177
|
-
.string()
|
|
178
|
-
.optional()
|
|
179
|
-
.describe('ID of the collection/group to place the new space in.'),
|
|
180
|
-
},
|
|
137
|
+
createDocSpaceSchema,
|
|
181
138
|
async (args) => callWriteApi({ tool: 'create-doc-space', ...args })
|
|
182
139
|
)
|
|
183
140
|
|
|
184
|
-
// Mirrors PublicAPIUpdateDocSpaceRequestSchema in @archbee/data-access, which
|
|
185
|
-
// this standalone package cannot import. The API re-validates with the real
|
|
186
|
-
// schema, so this only has to describe the shape well enough for the model;
|
|
187
|
-
// publicAccessControlPart passes unknown keys through so newer access-control
|
|
188
|
-
// fields keep working without a release here.
|
|
189
|
-
const emailListSchema = z.array(z.object({ email: z.string() }))
|
|
190
|
-
|
|
191
|
-
const publicAccessControlPartSchema = z
|
|
192
|
-
.object({
|
|
193
|
-
publicProtectionTypes: z
|
|
194
|
-
.array(
|
|
195
|
-
z.enum([
|
|
196
|
-
'None',
|
|
197
|
-
'Password',
|
|
198
|
-
'Guest accounts',
|
|
199
|
-
'Private Accounts',
|
|
200
|
-
'Private Link',
|
|
201
|
-
'Magic Link',
|
|
202
|
-
'JWT',
|
|
203
|
-
'SAML',
|
|
204
|
-
'OIDC',
|
|
205
|
-
])
|
|
206
|
-
)
|
|
207
|
-
.optional(),
|
|
208
|
-
publicPassword: z.string().optional(),
|
|
209
|
-
publicGuestAccounts: z
|
|
210
|
-
.array(z.object({ email: z.string(), password: z.string() }))
|
|
211
|
-
.optional(),
|
|
212
|
-
publicMagicLinkAccounts: emailListSchema.optional(),
|
|
213
|
-
publicPrivateAccounts: emailListSchema.optional(),
|
|
214
|
-
jwtValidationType: z.string().optional(),
|
|
215
|
-
jwtKeyUrl: z.string().optional(),
|
|
216
|
-
jwtSecret: z.string().optional(),
|
|
217
|
-
jwtRedirectURL: z.string().optional(),
|
|
218
|
-
samlMetadata: z.string().optional(),
|
|
219
|
-
samlEntityId: z.string().optional(),
|
|
220
|
-
conditionalRuleId: z.string().optional(),
|
|
221
|
-
})
|
|
222
|
-
.passthrough()
|
|
223
|
-
|
|
224
141
|
server.tool(
|
|
225
142
|
'update_doc_space',
|
|
226
|
-
'Update
|
|
227
|
-
|
|
228
|
-
hostnamePart: z
|
|
229
|
-
.object({ hostname: z.string(), hostnamePath: z.string() })
|
|
230
|
-
.optional()
|
|
231
|
-
.describe('Custom hostname configuration for the space.'),
|
|
232
|
-
spaceLinks: z
|
|
233
|
-
.array(z.object({ label: z.string(), docSpaceId: z.string() }))
|
|
234
|
-
.optional()
|
|
235
|
-
.describe(
|
|
236
|
-
'Links to other spaces. The list should start with the current space.'
|
|
237
|
-
),
|
|
238
|
-
publicAccessControlPart: publicAccessControlPartSchema
|
|
239
|
-
.optional()
|
|
240
|
-
.describe('Public access control and authentication configuration.'),
|
|
241
|
-
},
|
|
143
|
+
'Update an Archbee doc space: rename it, or change its icon, hostname, space links or public access control. Only the provided parts are changed, and at least one must be provided. The response echoes the space name and icon, and get_all_docs / get_doc report the name too, so a rename can be verified.',
|
|
144
|
+
updateDocSpaceSchema,
|
|
242
145
|
async (args) => callWriteApi({ tool: 'update-doc-space', ...args })
|
|
243
146
|
)
|
|
244
147
|
|
|
245
148
|
server.tool(
|
|
246
149
|
'delete_doc_space',
|
|
247
|
-
'Permanently delete
|
|
248
|
-
|
|
249
|
-
async () => callWriteApi({ tool: 'delete-doc-space' })
|
|
150
|
+
'Permanently delete an Archbee doc space together with every document inside it. This is destructive and cannot be undone. With a space API key the space deleted is the one SPACE_ID points at, so that key dies with it and no further tool call will work; with a team key it is the space named by docSpaceId. Ask the user to confirm before calling this tool.',
|
|
151
|
+
deleteDocSpaceSchema,
|
|
152
|
+
async (args) => callWriteApi({ tool: 'delete-doc-space', ...args })
|
|
250
153
|
)
|
|
251
154
|
|
|
252
155
|
server.tool(
|
|
253
156
|
'create_space_group',
|
|
254
157
|
'Create a new space group (collection of doc spaces) in the current Archbee team. Requires a team admin.',
|
|
255
|
-
|
|
256
|
-
name: z.string().describe('Name of the new space group.'),
|
|
257
|
-
isAiEnabled: z
|
|
258
|
-
.boolean()
|
|
259
|
-
.optional()
|
|
260
|
-
.describe('Enable AI features for the space group.'),
|
|
261
|
-
isReviewSystemEnabled: z
|
|
262
|
-
.boolean()
|
|
263
|
-
.optional()
|
|
264
|
-
.describe('Enable the review/approval workflow for the space group.'),
|
|
265
|
-
isBranchingSystemEnabled: z
|
|
266
|
-
.boolean()
|
|
267
|
-
.optional()
|
|
268
|
-
.describe(
|
|
269
|
-
'Enable the branching (git-style) workflow for the space group.'
|
|
270
|
-
),
|
|
271
|
-
},
|
|
158
|
+
createSpaceGroupSchema,
|
|
272
159
|
async (args) => callWriteApi({ tool: 'create-space-group', ...args })
|
|
273
160
|
)
|
|
274
161
|
|
|
275
162
|
server.tool(
|
|
276
163
|
'delete_space_group',
|
|
277
164
|
'Delete a space group (collection of doc spaces) from the current Archbee team. Requires a team admin. The group must already be empty: move or delete every doc space it still contains first, otherwise the call is rejected.',
|
|
278
|
-
|
|
279
|
-
docSpaceGroupId: z.string().describe('ID of the space group to delete.'),
|
|
280
|
-
},
|
|
165
|
+
deleteSpaceGroupSchema,
|
|
281
166
|
async (args) => callWriteApi({ tool: 'delete-space-group', ...args })
|
|
282
167
|
)
|
|
283
168
|
|
|
169
|
+
server.tool(
|
|
170
|
+
'create_category',
|
|
171
|
+
'Create a category (a folder in the space navigation) in an Archbee doc space. A category holds documents but has no content of its own. To put a document inside it, pass the returned categoryId as `parentDocId` on create_doc or update_doc.',
|
|
172
|
+
createCategorySchema,
|
|
173
|
+
async (args) => callWriteApi({ tool: 'create-category', ...args })
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
server.tool(
|
|
177
|
+
'delete_category',
|
|
178
|
+
'Delete a category from an Archbee doc space. The category must already be empty: move or delete the documents inside it first, otherwise the call is rejected. Deleting a category never deletes documents.',
|
|
179
|
+
deleteCategorySchema,
|
|
180
|
+
async (args) => callWriteApi({ tool: 'delete-category', ...args })
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
server.tool(
|
|
184
|
+
'list_templates',
|
|
185
|
+
'List the document templates saved in the Archbee organization (Reusables → Templates), each with its id, name and content as markdown. Use apply_template to create a document from one.',
|
|
186
|
+
listTemplatesSchema,
|
|
187
|
+
async () => callMcpApi({ tool: 'list-templates' })
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
server.tool(
|
|
191
|
+
'create_template',
|
|
192
|
+
'Save a new document template in the Archbee organization, from Markdown or MDX content. A template is a starting point for new documents; it is not itself a published page.',
|
|
193
|
+
createTemplateSchema,
|
|
194
|
+
async (args) => callWriteApi({ tool: 'create-template', ...args })
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
server.tool(
|
|
198
|
+
'apply_template',
|
|
199
|
+
'Create a new Archbee document from a saved template. The template content is copied verbatim, including blocks markdown cannot express (API endpoints, diagrams). The template itself is unchanged.',
|
|
200
|
+
applyTemplateSchema,
|
|
201
|
+
async (args) => callWriteApi({ tool: 'apply-template', ...args })
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
server.tool(
|
|
205
|
+
'list_content_snippets',
|
|
206
|
+
'List the reusable content snippets saved in the Archbee organization (Reusables → Content snippets), each with its id, name and content as markdown. A snippet is a block of content embedded into many documents and edited in one place.',
|
|
207
|
+
listContentSnippetsSchema,
|
|
208
|
+
async () => callMcpApi({ tool: 'list-content-snippets' })
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
server.tool(
|
|
212
|
+
'create_content_snippet',
|
|
213
|
+
'Create a reusable content snippet in the Archbee organization, from Markdown or MDX content. Requires a Scaling or Enterprise subscription.',
|
|
214
|
+
createContentSnippetSchema,
|
|
215
|
+
async (args) => callWriteApi({ tool: 'create-content-snippet', ...args })
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
server.tool(
|
|
219
|
+
'update_content_snippet',
|
|
220
|
+
'Update a reusable content snippet: rename it, replace its content, or both. The change reaches every document the snippet is embedded in. At least one of name or content must be provided.',
|
|
221
|
+
updateContentSnippetSchema,
|
|
222
|
+
async (args) => callWriteApi({ tool: 'update-content-snippet', ...args })
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
server.tool(
|
|
226
|
+
'delete_content_snippet',
|
|
227
|
+
'Permanently delete a reusable content snippet from the Archbee organization. Documents that embed it lose that content. This cannot be undone — ask the user to confirm before calling this tool.',
|
|
228
|
+
deleteContentSnippetSchema,
|
|
229
|
+
async (args) => callWriteApi({ tool: 'delete-content-snippet', ...args })
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
server.tool(
|
|
233
|
+
'list_variables',
|
|
234
|
+
'List the content variables and glossary terms saved in the Archbee organization (Reusables → Variables / Glossary), each with its id, name, value and per-space or per-language overrides.',
|
|
235
|
+
listVariablesSchema,
|
|
236
|
+
async (args) => callMcpApi({ tool: 'list-variables', ...args })
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
server.tool(
|
|
240
|
+
'create_variable',
|
|
241
|
+
'Create a content variable (or a glossary term) in the Archbee organization. A variable is referenced by name inside document content and resolved at render time. Requires a Scaling or Enterprise subscription.',
|
|
242
|
+
createVariableSchema,
|
|
243
|
+
async (args) => callWriteApi({ tool: 'create-variable', ...args })
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
server.tool(
|
|
247
|
+
'update_variable',
|
|
248
|
+
'Update a content variable or glossary term. Only the provided fields change, and at least one must be provided. The new value reaches every document that references it.',
|
|
249
|
+
updateVariableSchema,
|
|
250
|
+
async (args) => callWriteApi({ tool: 'update-variable', ...args })
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
server.tool(
|
|
254
|
+
'delete_variable',
|
|
255
|
+
'Permanently delete a content variable or glossary term from the Archbee organization. Documents that reference it by name stop resolving. Ask the user to confirm before calling this tool.',
|
|
256
|
+
deleteVariableSchema,
|
|
257
|
+
async (args) => callWriteApi({ tool: 'delete-variable', ...args })
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
// Origin of the Archbee API the key belongs to, same variable the CLI takes.
|
|
261
|
+
// app.archbee.com/api is being phased out, so the default is api.archbee.com.
|
|
262
|
+
const apiMcpUrl = (): string | null => {
|
|
263
|
+
const apiUrlInput = (process.env.ARCHBEE_API_URL || '').trim()
|
|
264
|
+
|
|
265
|
+
if (!apiUrlInput) {
|
|
266
|
+
return 'https://api.archbee.com/api/public-mcp'
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
try {
|
|
270
|
+
return new URL('/api/public-mcp', apiUrlInput).toString()
|
|
271
|
+
} catch {
|
|
272
|
+
return null
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
284
276
|
const processUrl = (urlInput: string): string | null => {
|
|
285
277
|
try {
|
|
286
278
|
const url = new URL(urlInput)
|
|
@@ -295,11 +287,32 @@ const processUrl = (urlInput: string): string | null => {
|
|
|
295
287
|
}
|
|
296
288
|
}
|
|
297
289
|
|
|
290
|
+
// A team key authenticates on its own, so team-level tools need no space at all.
|
|
291
|
+
// A space key carries no space id, so it travels packed with one.
|
|
292
|
+
const authorizationHeader = (docSpaceId: string): string => {
|
|
293
|
+
const apiKey = process.env.API_KEY || ''
|
|
294
|
+
|
|
295
|
+
if (!apiKey) {
|
|
296
|
+
return ''
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (usesTeamApiKey()) {
|
|
300
|
+
return `Bearer ${apiKey}`
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return docSpaceId
|
|
304
|
+
? `Bearer ${Buffer.from(`${docSpaceId}~${apiKey}`).toString('base64')}`
|
|
305
|
+
: ''
|
|
306
|
+
}
|
|
307
|
+
|
|
298
308
|
const callMcpApi = async (params: McpApiParams): Promise<CallToolResult> => {
|
|
299
309
|
const urlInput = process.env.API_BASE || ''
|
|
300
|
-
const
|
|
310
|
+
const teamMode = usesTeamApiKey()
|
|
311
|
+
const docSpaceIdInput = teamMode
|
|
312
|
+
? params.docSpaceId || ''
|
|
313
|
+
: process.env.SPACE_ID || ''
|
|
301
314
|
|
|
302
|
-
if (!urlInput && !docSpaceIdInput) {
|
|
315
|
+
if (!teamMode && !urlInput && !docSpaceIdInput) {
|
|
303
316
|
return {
|
|
304
317
|
content: [{ type: 'text', text: 'API base URL or docSpaceId not set.' }],
|
|
305
318
|
isError: true,
|
|
@@ -313,28 +326,33 @@ const callMcpApi = async (params: McpApiParams): Promise<CallToolResult> => {
|
|
|
313
326
|
}
|
|
314
327
|
}
|
|
315
328
|
|
|
316
|
-
const urlMcp = urlInput
|
|
317
|
-
? processUrl(urlInput)
|
|
318
|
-
: 'https://app.archbee.com/api/public-mcp'
|
|
329
|
+
const urlMcp = urlInput ? processUrl(urlInput) : apiMcpUrl()
|
|
319
330
|
|
|
320
331
|
if (urlMcp === null) {
|
|
321
332
|
return {
|
|
322
|
-
content: [
|
|
333
|
+
content: [
|
|
334
|
+
{
|
|
335
|
+
type: 'text',
|
|
336
|
+
text: 'Invalid API base URL or ARCHBEE_API_URL format.',
|
|
337
|
+
},
|
|
338
|
+
],
|
|
323
339
|
isError: true,
|
|
324
340
|
}
|
|
325
341
|
}
|
|
326
342
|
|
|
343
|
+
const authorization = authorizationHeader(docSpaceIdInput)
|
|
344
|
+
|
|
327
345
|
try {
|
|
328
346
|
let dataText: string
|
|
329
347
|
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
348
|
+
if (authorization) {
|
|
349
|
+
if (docSpaceIdInput) {
|
|
350
|
+
params.docSpaceId = docSpaceIdInput
|
|
351
|
+
}
|
|
334
352
|
|
|
335
353
|
const response = await axios.post(urlMcp, params, {
|
|
336
354
|
headers: {
|
|
337
|
-
Authorization:
|
|
355
|
+
Authorization: authorization,
|
|
338
356
|
'Content-Type': 'application/json',
|
|
339
357
|
},
|
|
340
358
|
timeout: 30000,
|
|
@@ -366,14 +384,17 @@ const callMcpApi = async (params: McpApiParams): Promise<CallToolResult> => {
|
|
|
366
384
|
// made with a PUBLISHED-/PREVIEW- snapshot credential. Both cases fail here with
|
|
367
385
|
// an explanation rather than as an opaque rejection from the server.
|
|
368
386
|
const callWriteApi = async (params: McpApiParams): Promise<CallToolResult> => {
|
|
369
|
-
const
|
|
387
|
+
const teamMode = usesTeamApiKey()
|
|
388
|
+
const docSpaceIdInput = teamMode
|
|
389
|
+
? params.docSpaceId || ''
|
|
390
|
+
: process.env.SPACE_ID || ''
|
|
370
391
|
|
|
371
|
-
if (!
|
|
392
|
+
if (!process.env.API_KEY || (!teamMode && !docSpaceIdInput)) {
|
|
372
393
|
return {
|
|
373
394
|
content: [
|
|
374
395
|
{
|
|
375
396
|
type: 'text',
|
|
376
|
-
text: 'Write tools need
|
|
397
|
+
text: 'Write tools need an API_KEY, plus SPACE_ID when the key is a space key. The API_BASE configuration is read-only.',
|
|
377
398
|
},
|
|
378
399
|
],
|
|
379
400
|
isError: true,
|
|
@@ -388,7 +409,7 @@ const callWriteApi = async (params: McpApiParams): Promise<CallToolResult> => {
|
|
|
388
409
|
content: [
|
|
389
410
|
{
|
|
390
411
|
type: 'text',
|
|
391
|
-
text: '
|
|
412
|
+
text: 'The target space is a published/preview snapshot, which cannot be written to. Use the live space id from the space URL in the Archbee app.',
|
|
392
413
|
},
|
|
393
414
|
],
|
|
394
415
|
isError: true,
|