@ferrfleet/mcp 10.1.0 → 10.13.2

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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=api-base.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-base.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/api-base.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,61 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { fleetRequest, orgIdSchema } from '../api-base.js';
3
+ const mockFetch = vi.fn();
4
+ vi.stubGlobal('fetch', mockFetch);
5
+ const ORG_ID = '3f0c6a52-8d1e-4b7a-9c2f-5e6d7a8b9c01';
6
+ const OTHER_ORG_ID = '7a1d9e34-2b5c-4f80-8e6a-1c3b5d7f9a02';
7
+ function ok() {
8
+ const body = { ok: true };
9
+ return {
10
+ ok: true,
11
+ status: 200,
12
+ text: () => Promise.resolve(JSON.stringify(body)),
13
+ json: () => Promise.resolve(body),
14
+ };
15
+ }
16
+ describe('fleetRequest org header', () => {
17
+ beforeEach(() => {
18
+ mockFetch.mockReset();
19
+ mockFetch.mockResolvedValue(ok());
20
+ });
21
+ afterEach(() => {
22
+ delete process.env.FERRFLEET_ORG_ID;
23
+ });
24
+ it('sends x-ferrfleet-org when FERRFLEET_ORG_ID is set', async () => {
25
+ process.env.FERRFLEET_ORG_ID = ORG_ID;
26
+ await fleetRequest('/agents', { token: 't' });
27
+ const init = mockFetch.mock.calls[0][1];
28
+ expect(init.headers['x-ferrfleet-org']).toBe(ORG_ID);
29
+ expect(init.headers['x-ferrfleet-api-version']).toBeDefined();
30
+ });
31
+ it('sends no org header when FERRFLEET_ORG_ID is unset', async () => {
32
+ await fleetRequest('/agents', { token: 't' });
33
+ const init = mockFetch.mock.calls[0][1];
34
+ expect(init.headers).not.toHaveProperty('x-ferrfleet-org');
35
+ });
36
+ it('rejects an invalid FERRFLEET_ORG_ID without calling fetch', async () => {
37
+ process.env.FERRFLEET_ORG_ID = 'not-a-uuid';
38
+ await expect(fleetRequest('/agents', { token: 't' })).rejects.toThrow(/FERRFLEET_ORG_ID/);
39
+ expect(mockFetch).not.toHaveBeenCalled();
40
+ });
41
+ it('sends the per-call org id when no env default is set', async () => {
42
+ await fleetRequest('/agents', { token: 't', orgId: ORG_ID });
43
+ expect(mockFetch.mock.calls[0][1].headers['x-ferrfleet-org']).toBe(ORG_ID);
44
+ });
45
+ it('prefers the per-call org id over FERRFLEET_ORG_ID', async () => {
46
+ process.env.FERRFLEET_ORG_ID = ORG_ID;
47
+ await fleetRequest('/agents', { token: 't', orgId: OTHER_ORG_ID });
48
+ expect(mockFetch.mock.calls[0][1].headers['x-ferrfleet-org']).toBe(OTHER_ORG_ID);
49
+ });
50
+ it('rejects an invalid per-call org id without calling fetch, even with a valid env default', async () => {
51
+ process.env.FERRFLEET_ORG_ID = ORG_ID;
52
+ await expect(fleetRequest('/agents', { token: 't', orgId: 'nope' })).rejects.toThrow(/org_id/);
53
+ expect(mockFetch).not.toHaveBeenCalled();
54
+ });
55
+ it('org_id schema is optional and only accepts UUIDs', () => {
56
+ expect(orgIdSchema.safeParse(undefined).success).toBe(true);
57
+ expect(orgIdSchema.safeParse(ORG_ID).success).toBe(true);
58
+ expect(orgIdSchema.safeParse('nope').success).toBe(false);
59
+ expect(orgIdSchema.safeParse('').success).toBe(false);
60
+ });
61
+ });
@@ -1,9 +1,12 @@
1
+ import { z } from 'zod';
1
2
  export declare const FLEET_API_URL: string;
2
3
  export declare const FLEET_API_VERSION: string;
4
+ export declare const orgIdSchema: z.ZodOptional<z.ZodGUID>;
3
5
  interface FleetRequestOptions {
4
6
  method?: string;
5
7
  body?: unknown;
6
8
  token: string;
9
+ orgId?: string | undefined;
7
10
  }
8
11
  export declare function fleetRequest<T>(path: string, options: FleetRequestOptions): Promise<T>;
9
12
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"api-base.d.ts","sourceRoot":"","sources":["../src/api-base.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,QAA+D,CAAC;AAI1F,eAAO,MAAM,iBAAiB,QAAoD,CAAC;AAEnF,UAAU,mBAAmB;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAQtF"}
1
+ {"version":3,"file":"api-base.d.ts","sourceRoot":"","sources":["../src/api-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,aAAa,QAA+D,CAAC;AAK1F,eAAO,MAAM,iBAAiB,QAAoD,CAAC;AAEnF,eAAO,MAAM,WAAW,0BAGyC,CAAC;AAElE,UAAU,mBAAmB;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAiBD,wBAAsB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAQ5F"}
package/dist/api-base.js CHANGED
@@ -1,13 +1,34 @@
1
+ import { z } from 'zod';
1
2
  import { apiRequest } from '@ferrlabs/mcp-core';
2
3
  export const FLEET_API_URL = process.env.FERRFLEET_API_URL ?? 'https://api.ferrfleet.com';
3
4
  const API_VERSION_HEADER = 'x-ferrfleet-api-version';
5
+ const ORG_HEADER = 'x-ferrfleet-org';
4
6
  export const FLEET_API_VERSION = process.env.FERRFLEET_API_VERSION ?? '2026-08-04';
5
- export function fleetRequest(path, options) {
6
- const { token, ...rest } = options;
7
+ export const orgIdSchema = z
8
+ .guid()
9
+ .optional()
10
+ .describe('Organization id. Find it with list_ferrfleet_orgs.');
11
+ function orgHeader(orgId) {
12
+ if (orgId !== undefined) {
13
+ if (!z.guid().safeParse(orgId).success) {
14
+ throw new Error('org_id must be a UUID');
15
+ }
16
+ return { [ORG_HEADER]: orgId };
17
+ }
18
+ const fallback = process.env.FERRFLEET_ORG_ID;
19
+ if (fallback === undefined || fallback === '')
20
+ return {};
21
+ if (!z.guid().safeParse(fallback).success) {
22
+ throw new Error('FERRFLEET_ORG_ID must be a UUID');
23
+ }
24
+ return { [ORG_HEADER]: fallback };
25
+ }
26
+ export async function fleetRequest(path, options) {
27
+ const { token, orgId, ...rest } = options;
7
28
  return apiRequest(path, {
8
29
  ...rest,
9
30
  token,
10
31
  baseUrl: FLEET_API_URL,
11
- headers: { [API_VERSION_HEADER]: FLEET_API_VERSION },
32
+ headers: { [API_VERSION_HEADER]: FLEET_API_VERSION, ...orgHeader(orgId) },
12
33
  });
13
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKpD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAIhD"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAWpD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAUhD"}
package/dist/register.js CHANGED
@@ -1,8 +1,20 @@
1
1
  import { registerAgentTools } from './tools/agents.js';
2
+ import { registerConnectorTools } from './tools/connectors.js';
3
+ import { registerGithubTools } from './tools/github.js';
4
+ import { registerMarketplaceTools } from './tools/marketplace.js';
5
+ import { registerOrgTools } from './tools/orgs.js';
6
+ import { registerRepoTools } from './tools/repos.js';
7
+ import { registerRunnerPoolTools } from './tools/runner-pools.js';
2
8
  import { registerRunTools } from './tools/runs.js';
3
9
  import { registerRunReviewPrompt } from './prompts/run-review.js';
4
10
  export function register(server) {
5
11
  registerAgentTools(server);
12
+ registerConnectorTools(server);
13
+ registerGithubTools(server);
14
+ registerMarketplaceTools(server);
15
+ registerOrgTools(server);
16
+ registerRepoTools(server);
17
+ registerRunnerPoolTools(server);
6
18
  registerRunTools(server);
7
19
  registerRunReviewPrompt(server);
8
20
  }
@@ -1,4 +1,4 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
2
  process.env.FERRLABS_API_TOKEN = 'test-token';
3
3
  const handlers = new Map();
4
4
  const schemas = new Map();
@@ -28,6 +28,9 @@ function lastCall() {
28
28
  };
29
29
  }
30
30
  const FLEET = 'https://api.ferrfleet.com';
31
+ const ORG_ID = '3f0c6a52-8d1e-4b7a-9c2f-5e6d7a8b9c01';
32
+ const POOL_ID = '0192f3a4-5b6c-7d8e-9f01-23456789abcd';
33
+ const ENV_ORG_ID = '7a1d9e34-2b5c-4f80-8e6a-1c3b5d7f9a02';
31
34
  describe('ferrfleet tools', () => {
32
35
  beforeEach(async () => {
33
36
  vi.clearAllMocks();
@@ -36,8 +39,20 @@ describe('ferrfleet tools', () => {
36
39
  mockFetch.mockResolvedValue(ok());
37
40
  const { registerAgentTools } = await import('../agents.js');
38
41
  const { registerRunTools } = await import('../runs.js');
42
+ const { registerOrgTools } = await import('../orgs.js');
43
+ const { registerRunnerPoolTools } = await import('../runner-pools.js');
39
44
  registerAgentTools(mockServer);
40
45
  registerRunTools(mockServer);
46
+ registerOrgTools(mockServer);
47
+ const { registerRepoTools } = await import('../repos.js');
48
+ const { registerGithubTools } = await import('../github.js');
49
+ registerRunnerPoolTools(mockServer);
50
+ registerRepoTools(mockServer);
51
+ registerGithubTools(mockServer);
52
+ const { registerMarketplaceTools } = await import('../marketplace.js');
53
+ const { registerConnectorTools } = await import('../connectors.js');
54
+ registerMarketplaceTools(mockServer);
55
+ registerConnectorTools(mockServer);
41
56
  });
42
57
  it('every call goes to the FerrFleet API', async () => {
43
58
  await handlers.get('list_agents')({});
@@ -86,4 +101,357 @@ describe('ferrfleet tools', () => {
86
101
  expect(limit.safeParse(0).success).toBe(false);
87
102
  expect(limit.safeParse(101).success).toBe(false);
88
103
  });
104
+ it('create_agent posts only the fields given', async () => {
105
+ await handlers.get('create_agent')({
106
+ id: 'triage-bot',
107
+ name: 'Triage bot',
108
+ prompt: 'Triage issues',
109
+ org_id: ORG_ID,
110
+ });
111
+ const call = lastCall();
112
+ expect(call.url).toBe(`${FLEET}/agents`);
113
+ expect(call.method).toBe('POST');
114
+ expect(call.body).toEqual({ id: 'triage-bot', name: 'Triage bot', prompt: 'Triage issues' });
115
+ });
116
+ it('create_agent forwards the optional fields', async () => {
117
+ const params = {
118
+ id: 'triage-bot',
119
+ name: 'Triage bot',
120
+ prompt: 'Triage issues',
121
+ additional_prompt: 'Be brief',
122
+ model: 'sonnet',
123
+ working_dir: '/repo',
124
+ description: 'Triages',
125
+ notify_url: 'https://example.com/hook',
126
+ };
127
+ await handlers.get('create_agent')(params);
128
+ expect(lastCall().body).toEqual(params);
129
+ });
130
+ it('create_agent requires id, name and prompt', () => {
131
+ const shape = schemas.get('create_agent');
132
+ expect(shape.id.safeParse(undefined).success).toBe(false);
133
+ expect(shape.name.safeParse(undefined).success).toBe(false);
134
+ expect(shape.prompt.safeParse(undefined).success).toBe(false);
135
+ expect(shape.model.safeParse(undefined).success).toBe(true);
136
+ });
137
+ it('create_agent only accepts ids the API accepts', () => {
138
+ const id = schemas.get('create_agent').id;
139
+ expect(id.safeParse('triage-bot').success).toBe(true);
140
+ expect(id.safeParse('ab').success).toBe(true);
141
+ expect(id.safeParse('Triage').success).toBe(false);
142
+ expect(id.safeParse('a').success).toBe(false);
143
+ expect(id.safeParse('-bot').success).toBe(false);
144
+ expect(id.safeParse('bot-').success).toBe(false);
145
+ expect(id.safeParse('a'.repeat(65)).success).toBe(false);
146
+ });
147
+ it('create_agent exposes no fields the API ignores', () => {
148
+ const keys = Object.keys(schemas.get('create_agent'));
149
+ expect(keys).not.toContain('runner_mode');
150
+ expect(keys).not.toContain('enabled');
151
+ expect(keys).not.toContain('options');
152
+ });
153
+ it('update_agent patches the agent with only the fields given', async () => {
154
+ await handlers.get('update_agent')({ agent_id: 'a1', runner_mode: 'external' });
155
+ const call = lastCall();
156
+ expect(call.url).toBe(`${FLEET}/agents/a1`);
157
+ expect(call.method).toBe('PATCH');
158
+ expect(call.body).toEqual({ runner_mode: 'external' });
159
+ });
160
+ it('update_agent keeps falsy values that are real changes', async () => {
161
+ await handlers.get('update_agent')({
162
+ agent_id: 'a1',
163
+ enabled: false,
164
+ model: '',
165
+ additional_prompt: '',
166
+ });
167
+ expect(lastCall().body).toEqual({ enabled: false, model: '', additional_prompt: '' });
168
+ });
169
+ it('update_agent refuses an empty update without calling the API', async () => {
170
+ const result = await handlers.get('update_agent')({ agent_id: 'a1' });
171
+ expect(result).toMatchObject({ isError: true });
172
+ expect(mockFetch).not.toHaveBeenCalled();
173
+ });
174
+ it('update_agent only accepts the runner modes the API knows', () => {
175
+ const mode = schemas.get('update_agent').runner_mode;
176
+ expect(mode.safeParse('managed').success).toBe(true);
177
+ expect(mode.safeParse('external').success).toBe(true);
178
+ expect(mode.safeParse('hybrid').success).toBe(false);
179
+ expect(mode.safeParse('External').success).toBe(false);
180
+ });
181
+ it('update_agent sets the runner pool by id', async () => {
182
+ await handlers.get('update_agent')({ agent_id: 'a1', runner_pool_id: POOL_ID });
183
+ expect(lastCall().body).toEqual({ runner_pool_id: POOL_ID });
184
+ });
185
+ it('update_agent sends a null runner_pool_id to detach the pool', async () => {
186
+ await handlers.get('update_agent')({ agent_id: 'a1', runner_pool_id: null });
187
+ expect(lastCall().body).toEqual({ runner_pool_id: null });
188
+ expect(lastCall().body).toHaveProperty('runner_pool_id', null);
189
+ });
190
+ it('update_agent leaves runner_pool_id out of the body when omitted', async () => {
191
+ await handlers.get('update_agent')({ agent_id: 'a1', enabled: true });
192
+ expect(lastCall().body).not.toHaveProperty('runner_pool_id');
193
+ });
194
+ it('update_agent accepts a pool change as the only field', async () => {
195
+ const result = await handlers.get('update_agent')({ agent_id: 'a1', runner_pool_id: null });
196
+ expect(result.isError).toBeUndefined();
197
+ expect(mockFetch).toHaveBeenCalledTimes(1);
198
+ });
199
+ it('update_agent only accepts a uuid or null as runner_pool_id', () => {
200
+ const pool = schemas.get('update_agent').runner_pool_id;
201
+ expect(pool.safeParse(POOL_ID).success).toBe(true);
202
+ expect(pool.safeParse(null).success).toBe(true);
203
+ expect(pool.safeParse(undefined).success).toBe(true);
204
+ expect(pool.safeParse('default').success).toBe(false);
205
+ expect(pool.safeParse('').success).toBe(false);
206
+ });
207
+ it('list_runner_pools reads the runner pool collection and returns it unchanged', async () => {
208
+ const pools = [{ id: POOL_ID, name: 'build-farm', status: 'active' }];
209
+ mockFetch.mockResolvedValue(ok(pools));
210
+ const result = await handlers.get('list_runner_pools')({});
211
+ const call = lastCall();
212
+ expect(call.url).toBe(`${FLEET}/runner-pools`);
213
+ expect(call.method).toBe('GET');
214
+ expect(JSON.parse(result.content[0].text)).toEqual(pools);
215
+ });
216
+ it('exposes no tool that creates or rotates a pool token', () => {
217
+ const names = [...handlers.keys()].filter((name) => /pool|token/.test(name));
218
+ expect(names).toEqual(['list_runner_pools']);
219
+ });
220
+ it('bind_repo upserts the binding with the repository and agent', async () => {
221
+ await handlers.get('bind_repo')({
222
+ repo_full_name: 'IdleWarden/idlewarden',
223
+ agent_id: 'pr-review',
224
+ });
225
+ const call = lastCall();
226
+ expect(call.url).toBe(`${FLEET}/repos/bindings`);
227
+ expect(call.method).toBe('POST');
228
+ expect(call.body).toEqual({ repo_full_name: 'IdleWarden/idlewarden', agent_id: 'pr-review' });
229
+ });
230
+ it('bind_repo keeps enabled=false so a binding can be switched off', async () => {
231
+ await handlers.get('bind_repo')({
232
+ repo_full_name: 'IdleWarden/idlewarden',
233
+ agent_id: 'pr-review',
234
+ enabled: false,
235
+ });
236
+ expect(lastCall().body).toEqual({
237
+ repo_full_name: 'IdleWarden/idlewarden',
238
+ agent_id: 'pr-review',
239
+ enabled: false,
240
+ });
241
+ });
242
+ it('bind_repo only accepts owner/name repositories', () => {
243
+ const repo = schemas.get('bind_repo').repo_full_name;
244
+ expect(repo.safeParse('IdleWarden/idlewarden').success).toBe(true);
245
+ expect(repo.safeParse('idlewarden').success).toBe(false);
246
+ expect(repo.safeParse('a/b/c').success).toBe(false);
247
+ expect(repo.safeParse('../agents').success).toBe(false);
248
+ });
249
+ it('list_repo_bindings reads the bindings collection', async () => {
250
+ mockFetch.mockResolvedValue(ok([]));
251
+ await handlers.get('list_repo_bindings')({});
252
+ const call = lastCall();
253
+ expect(call.url).toBe(`${FLEET}/repos/bindings`);
254
+ expect(call.method).toBe('GET');
255
+ });
256
+ it('create_github_connector posts a github connector with only the name', async () => {
257
+ await handlers.get('create_github_connector')({ name: 'github' });
258
+ const call = lastCall();
259
+ expect(call.url).toBe(`${FLEET}/connectors`);
260
+ expect(call.method).toBe('POST');
261
+ expect(call.body).toEqual({ type: 'github', name: 'github' });
262
+ });
263
+ it('create_github_connector only accepts names the API accepts', () => {
264
+ const name = schemas.get('create_github_connector').name;
265
+ expect(name.safeParse('github').success).toBe(true);
266
+ expect(name.safeParse('').success).toBe(false);
267
+ expect(name.safeParse('-github').success).toBe(false);
268
+ expect(name.safeParse('a/b').success).toBe(false);
269
+ });
270
+ it('list_github_installations reads the installations collection', async () => {
271
+ mockFetch.mockResolvedValue(ok([]));
272
+ await handlers.get('list_github_installations')({});
273
+ const call = lastCall();
274
+ expect(call.url).toBe(`${FLEET}/github/installations`);
275
+ expect(call.method).toBe('GET');
276
+ });
277
+ it('update_agent escapes the agent id', async () => {
278
+ await handlers.get('update_agent')({ agent_id: '../runs', enabled: true });
279
+ expect(lastCall().url).toBe(`${FLEET}/agents/..%2Fruns`);
280
+ });
281
+ it('list_marketplace_agents reads the catalog and returns it unchanged', async () => {
282
+ const templates = [{ id: 'pr-review', name: 'PR review', imported: false }];
283
+ mockFetch.mockResolvedValue(ok(templates));
284
+ const result = await handlers.get('list_marketplace_agents')({});
285
+ expect(lastCall().url).toBe(`${FLEET}/marketplace/agents`);
286
+ expect(lastCall().method).toBe('GET');
287
+ expect(JSON.parse(result.content[0].text)).toEqual(templates);
288
+ });
289
+ it('import_marketplace_agent escapes the template id and sends an empty body by default', async () => {
290
+ await handlers.get('import_marketplace_agent')({ template_id: '../agents' });
291
+ const call = lastCall();
292
+ expect(call.url).toBe(`${FLEET}/marketplace/agents/..%2Fagents/import`);
293
+ expect(call.method).toBe('POST');
294
+ expect(call.body).toEqual({});
295
+ });
296
+ it('import_marketplace_agent sends only the overrides given', async () => {
297
+ await handlers.get('import_marketplace_agent')({ template_id: 'pr-review', name: 'Mine' });
298
+ expect(lastCall().body).toEqual({ name: 'Mine' });
299
+ mockFetch.mockClear();
300
+ await handlers.get('import_marketplace_agent')({ template_id: 'pr-review', id: 'my-pr' });
301
+ expect(lastCall().body).toEqual({ id: 'my-pr' });
302
+ });
303
+ it('import_marketplace_agent only accepts ids the API accepts for agents', () => {
304
+ const id = schemas.get('import_marketplace_agent').id;
305
+ expect(id.safeParse('my-pr-agent').success).toBe(true);
306
+ expect(id.safeParse('My_Agent').success).toBe(false);
307
+ expect(id.safeParse('-bad').success).toBe(false);
308
+ expect(id.safeParse('a').success).toBe(false);
309
+ expect(id.safeParse('a'.repeat(65)).success).toBe(false);
310
+ });
311
+ it('list_connectors reads the connector collection', async () => {
312
+ const connectors = [{ id: 'c1', type: 'github', name: 'Gh', has_secret: true }];
313
+ mockFetch.mockResolvedValue(ok(connectors));
314
+ const result = await handlers.get('list_connectors')({});
315
+ expect(lastCall().url).toBe(`${FLEET}/connectors`);
316
+ expect(lastCall().method).toBe('GET');
317
+ expect(JSON.parse(result.content[0].text)).toEqual(connectors);
318
+ });
319
+ it('set_agent_connectors puts exactly the given list and escapes the agent id', async () => {
320
+ await handlers.get('set_agent_connectors')({
321
+ agent_id: '../runs',
322
+ connector_ids: ['c1', 'c2'],
323
+ });
324
+ const call = lastCall();
325
+ expect(call.url).toBe(`${FLEET}/agents/..%2Fruns/connectors`);
326
+ expect(call.method).toBe('PUT');
327
+ expect(call.body).toEqual({ connector_ids: ['c1', 'c2'] });
328
+ });
329
+ it('set_agent_connectors sends an empty list to detach everything', async () => {
330
+ await handlers.get('set_agent_connectors')({ agent_id: 'a1', connector_ids: [] });
331
+ expect(lastCall().body).toEqual({ connector_ids: [] });
332
+ });
333
+ it('set_agent_connectors requires the list and rejects empty ids', () => {
334
+ const ids = schemas.get('set_agent_connectors').connector_ids;
335
+ expect(ids.safeParse(undefined).success).toBe(false);
336
+ expect(ids.safeParse(['']).success).toBe(false);
337
+ expect(ids.safeParse(['c1']).success).toBe(true);
338
+ });
339
+ it('update_connector patches with only the fields given', async () => {
340
+ await handlers.get('update_connector')({ connector_id: 'c1', name: 'Renamed' });
341
+ const call = lastCall();
342
+ expect(call.url).toBe(`${FLEET}/connectors/c1`);
343
+ expect(call.method).toBe('PATCH');
344
+ expect(call.body).toEqual({ name: 'Renamed' });
345
+ });
346
+ it('update_connector sends config as given, without merging it client side', async () => {
347
+ await handlers.get('update_connector')({ connector_id: 'c1', config: { url: 'https://x' } });
348
+ expect(lastCall().body).toEqual({ config: { url: 'https://x' } });
349
+ });
350
+ it('update_connector refuses an empty update without calling the API', async () => {
351
+ const result = await handlers.get('update_connector')({ connector_id: 'c1' });
352
+ expect(result.isError).toBe(true);
353
+ expect(mockFetch).not.toHaveBeenCalled();
354
+ });
355
+ it('update_connector escapes the connector id', async () => {
356
+ await handlers.get('update_connector')({ connector_id: '../agents', name: 'x' });
357
+ expect(lastCall().url).toBe(`${FLEET}/connectors/..%2Fagents`);
358
+ });
359
+ it('update_connector does not expose the secret', async () => {
360
+ expect(Object.keys(schemas.get('update_connector'))).not.toContain('secret');
361
+ await handlers.get('update_connector')({ connector_id: 'c1', name: 'x', secret: 'hunter2' });
362
+ expect(lastCall().body).toEqual({ name: 'x' });
363
+ });
364
+ it('update_connector only accepts names the API accepts', () => {
365
+ const name = schemas.get('update_connector').name;
366
+ expect(name.safeParse('GitHub main_1').success).toBe(true);
367
+ expect(name.safeParse('').success).toBe(false);
368
+ expect(name.safeParse(' lead').success).toBe(false);
369
+ expect(name.safeParse('a'.repeat(64)).success).toBe(false);
370
+ });
371
+ it('update_connector only accepts an object as config', () => {
372
+ const config = schemas.get('update_connector').config;
373
+ expect(config.safeParse('x').success).toBe(false);
374
+ expect(config.safeParse(['a']).success).toBe(false);
375
+ });
376
+ describe('org selection', () => {
377
+ afterEach(() => {
378
+ delete process.env.FERRFLEET_ORG_ID;
379
+ });
380
+ const CALLS = [
381
+ ['list_agents', {}],
382
+ ['get_agent', { agent_id: 'a1' }],
383
+ ['trigger_agent_run', { agent_id: 'a1' }],
384
+ ['create_agent', { id: 'bot', name: 'Bot', prompt: 'Go' }],
385
+ ['update_agent', { agent_id: 'a1', enabled: true }],
386
+ ['list_runner_pools', {}],
387
+ ['list_marketplace_agents', {}],
388
+ ['import_marketplace_agent', { template_id: 't1' }],
389
+ ['list_connectors', {}],
390
+ ['set_agent_connectors', { agent_id: 'a1', connector_ids: [] }],
391
+ ['update_connector', { connector_id: 'c1', name: 'Gh' }],
392
+ ['list_runs', {}],
393
+ ['get_run', { run_id: 'r1' }],
394
+ ['get_run_transcript', { run_id: 'r1' }],
395
+ ];
396
+ it.each(CALLS)('%s sends the org_id param as x-ferrfleet-org', async (name, params) => {
397
+ await handlers.get(name)({ ...params, org_id: ORG_ID });
398
+ expect(lastCall().headers['x-ferrfleet-org']).toBe(ORG_ID);
399
+ });
400
+ it.each(CALLS)('%s declares an optional uuid org_id', (name) => {
401
+ const orgId = schemas.get(name).org_id;
402
+ expect(orgId.safeParse(undefined).success).toBe(true);
403
+ expect(orgId.safeParse(ORG_ID).success).toBe(true);
404
+ expect(orgId.safeParse('nope').success).toBe(false);
405
+ });
406
+ it.each(CALLS)('%s accepts the non RFC 4122 ids FerrLabs issues', (name) => {
407
+ const orgId = schemas.get(name).org_id;
408
+ expect(orgId.safeParse('019ddfca-92ba-e1e5-2a5d-7602d4b77ae6').success).toBe(true);
409
+ });
410
+ it('org_id is not forwarded in the update_agent body', async () => {
411
+ await handlers.get('update_agent')({ agent_id: 'a1', enabled: true, org_id: ORG_ID });
412
+ expect(lastCall().body).toEqual({ enabled: true });
413
+ });
414
+ it('org_id param overrides FERRFLEET_ORG_ID', async () => {
415
+ process.env.FERRFLEET_ORG_ID = ENV_ORG_ID;
416
+ await handlers.get('list_agents')({ org_id: ORG_ID });
417
+ expect(lastCall().headers['x-ferrfleet-org']).toBe(ORG_ID);
418
+ });
419
+ it('falls back to FERRFLEET_ORG_ID when org_id is absent', async () => {
420
+ process.env.FERRFLEET_ORG_ID = ENV_ORG_ID;
421
+ await handlers.get('list_agents')({});
422
+ expect(lastCall().headers['x-ferrfleet-org']).toBe(ENV_ORG_ID);
423
+ });
424
+ it('sends no org header when neither is set', async () => {
425
+ await handlers.get('list_agents')({});
426
+ expect(lastCall().headers).not.toHaveProperty('x-ferrfleet-org');
427
+ });
428
+ it('rejects an invalid org_id before any fetch', async () => {
429
+ await expect(handlers.get('list_agents')({ org_id: 'nope' })).rejects.toThrow(/org_id/);
430
+ expect(mockFetch).not.toHaveBeenCalled();
431
+ });
432
+ });
433
+ describe('list_ferrfleet_orgs', () => {
434
+ it('reads /orgs from the identity API, not FerrFleet, with no org header', async () => {
435
+ process.env.FERRFLEET_ORG_ID = ENV_ORG_ID;
436
+ mockFetch.mockResolvedValue(ok([]));
437
+ await handlers.get('list_ferrfleet_orgs')({});
438
+ const call = lastCall();
439
+ expect(call.method).toBe('GET');
440
+ expect(new URL(call.url).pathname).toMatch(/\/orgs$/);
441
+ expect(call.url.startsWith(FLEET)).toBe(false);
442
+ expect(call.headers).not.toHaveProperty('x-ferrfleet-org');
443
+ delete process.env.FERRFLEET_ORG_ID;
444
+ });
445
+ it('returns id, name, slug and role only', async () => {
446
+ mockFetch.mockResolvedValue(ok([
447
+ { id: ORG_ID, name: 'Acme', slug: 'acme', role: 'admin', member_count: 3 },
448
+ { id: ENV_ORG_ID, name: 'Beta', slug: 'beta', member_count: 1 },
449
+ ]));
450
+ const result = await handlers.get('list_ferrfleet_orgs')({});
451
+ expect(JSON.parse(result.content[0].text)).toEqual([
452
+ { id: ORG_ID, name: 'Acme', slug: 'acme', role: 'admin' },
453
+ { id: ENV_ORG_ID, name: 'Beta', slug: 'beta' },
454
+ ]);
455
+ });
456
+ });
89
457
  });
@@ -1,3 +1,4 @@
1
1
  import { type McpServer } from '@ferrlabs/mcp-core';
2
+ export declare const AGENT_ID_PATTERN: RegExp;
2
3
  export declare function registerAgentTools(server: McpServer): void;
3
4
  //# sourceMappingURL=agents.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/tools/agents.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAa1E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,QA2DnD"}
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/tools/agents.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAc1E,eAAO,MAAM,gBAAgB,QAAsC,CAAC;AAEpE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,QAqLnD"}