@slashfi/agents-sdk 0.33.2 → 0.34.1
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/dist/call-agent-schema.d.ts +408 -101
- package/dist/call-agent-schema.d.ts.map +1 -1
- package/dist/call-agent-schema.js +101 -9
- package/dist/call-agent-schema.js.map +1 -1
- package/dist/cjs/call-agent-schema.js +105 -10
- package/dist/cjs/call-agent-schema.js.map +1 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/server.js +22 -6
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/validate.js +2 -2
- package/dist/cjs/validate.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +18 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +23 -7
- package/dist/server.js.map +1 -1
- package/dist/validate.d.ts +15 -15
- package/dist/validate.js +2 -2
- package/dist/validate.js.map +1 -1
- package/package.json +1 -1
- package/src/call-agent-schema.test.ts +306 -0
- package/src/call-agent-schema.ts +127 -19
- package/src/index.ts +6 -0
- package/src/server.ts +45 -7
- package/src/validate.ts +2 -2
package/src/index.ts
CHANGED
|
@@ -384,6 +384,8 @@ export type { IntrospectOptions } from "./introspect.js";
|
|
|
384
384
|
export {
|
|
385
385
|
callAgentInputSchema,
|
|
386
386
|
callAgentRequestSchema,
|
|
387
|
+
callAgentValidationSchema,
|
|
388
|
+
callAgentToolInputSchema,
|
|
387
389
|
invokeActionSchema,
|
|
388
390
|
askActionSchema,
|
|
389
391
|
executeToolActionSchema,
|
|
@@ -393,6 +395,10 @@ export {
|
|
|
393
395
|
readResourcesActionSchema,
|
|
394
396
|
callerTypeSchema,
|
|
395
397
|
CALL_AGENT_ACTIONS,
|
|
398
|
+
nullTolerant,
|
|
399
|
+
stripNulls,
|
|
400
|
+
zodToOpenAiJsonSchema,
|
|
401
|
+
listAgentsValidationSchema,
|
|
396
402
|
} from "./call-agent-schema.js";
|
|
397
403
|
|
|
398
404
|
// ============================================
|
package/src/server.ts
CHANGED
|
@@ -48,8 +48,11 @@ import type { AgentDefinition, CallAgentRequest } from "./types.js";
|
|
|
48
48
|
|
|
49
49
|
import {
|
|
50
50
|
callAgentInputSchema,
|
|
51
|
+
callAgentValidationSchema,
|
|
51
52
|
listAgentsInputSchema,
|
|
52
|
-
|
|
53
|
+
listAgentsValidationSchema,
|
|
54
|
+
nullTolerant,
|
|
55
|
+
zodToOpenAiJsonSchema,
|
|
53
56
|
} from "./call-agent-schema.js";
|
|
54
57
|
|
|
55
58
|
// ============================================
|
|
@@ -146,6 +149,24 @@ export interface AgentServerOptions {
|
|
|
146
149
|
* ```
|
|
147
150
|
*/
|
|
148
151
|
resolveAuth?: (req: Request) => Promise<ResolvedAuth | null>;
|
|
152
|
+
/**
|
|
153
|
+
* Schema overrides for built-in MCP tools.
|
|
154
|
+
* When provided, these replace the default schemas for both
|
|
155
|
+
* JSON Schema generation (what LLMs see) and runtime validation.
|
|
156
|
+
*
|
|
157
|
+
* Schemas must be Zod schemas that are supersets of the defaults
|
|
158
|
+
* (e.g., extending the base action schemas with additional fields).
|
|
159
|
+
*
|
|
160
|
+
* The server automatically:
|
|
161
|
+
* - Converts to JSON Schema (openAi target) for tools/list
|
|
162
|
+
* - Wraps with nullTolerant() for validation
|
|
163
|
+
*/
|
|
164
|
+
schemas?: {
|
|
165
|
+
/** Override call_agent tool input schema (wraps callAgentRequestSchema) */
|
|
166
|
+
callAgent?: import("zod").ZodTypeAny;
|
|
167
|
+
/** Override list_agents tool input schema */
|
|
168
|
+
listAgents?: import("zod").ZodTypeAny;
|
|
169
|
+
};
|
|
149
170
|
/**
|
|
150
171
|
* Registry capabilities — advertised in MCP initialize response.
|
|
151
172
|
* When set, this server identifies as an agent registry (superset of MCP).
|
|
@@ -437,19 +458,23 @@ function resolveAgent(
|
|
|
437
458
|
// MCP Tool Definitions
|
|
438
459
|
// ============================================
|
|
439
460
|
|
|
440
|
-
function getToolDefinitions() {
|
|
461
|
+
function getToolDefinitions(schemas?: AgentServerOptions["schemas"]) {
|
|
441
462
|
return [
|
|
442
463
|
{
|
|
443
464
|
name: "call_agent",
|
|
444
465
|
description:
|
|
445
466
|
"Execute a tool on a registered agent. Provide the agent path and tool name.\n\nSupported actions:\n- invoke: Fire-and-forget agent invocation\n- ask: Invoke and wait for response\n- execute_tool: Call a specific tool on an agent\n- describe_tools: Get tool schemas for an agent\n- load: Get agent definition/system prompt\n- list_resources: List all resources available on an agent (docs, auth instructions, config schemas, etc.)\n- read_resources: Fetch one or more resources by URI",
|
|
446
|
-
inputSchema:
|
|
467
|
+
inputSchema: schemas?.callAgent
|
|
468
|
+
? zodToOpenAiJsonSchema(schemas.callAgent)
|
|
469
|
+
: callAgentInputSchema,
|
|
447
470
|
},
|
|
448
471
|
{
|
|
449
472
|
name: "list_agents",
|
|
450
473
|
description:
|
|
451
474
|
"List all registered agents and their available tools. Optionally search/filter by query using BM25 ranking.",
|
|
452
|
-
inputSchema:
|
|
475
|
+
inputSchema: schemas?.listAgents
|
|
476
|
+
? zodToOpenAiJsonSchema(schemas.listAgents)
|
|
477
|
+
: listAgentsInputSchema,
|
|
453
478
|
},
|
|
454
479
|
];
|
|
455
480
|
}
|
|
@@ -473,6 +498,15 @@ export function createAgentServer(
|
|
|
473
498
|
oauthIdentityProvider,
|
|
474
499
|
} = options;
|
|
475
500
|
|
|
501
|
+
// Build tool definitions and validation schemas from overrides
|
|
502
|
+
const toolDefs = getToolDefinitions(options.schemas);
|
|
503
|
+
const callAgentValidate = options.schemas?.callAgent
|
|
504
|
+
? nullTolerant(options.schemas.callAgent)
|
|
505
|
+
: callAgentValidationSchema;
|
|
506
|
+
const listAgentsValidate = options.schemas?.listAgents
|
|
507
|
+
? nullTolerant(options.schemas.listAgents)
|
|
508
|
+
: listAgentsValidationSchema;
|
|
509
|
+
|
|
476
510
|
// OIDC sign-in handler (if configured)
|
|
477
511
|
const oidcSignIn = options.oidcProvider
|
|
478
512
|
? createOIDCSignIn(options.oidcProvider)
|
|
@@ -518,7 +552,7 @@ export function createAgentServer(
|
|
|
518
552
|
|
|
519
553
|
case "tools/list":
|
|
520
554
|
return jsonRpcSuccess(request.id, {
|
|
521
|
-
tools:
|
|
555
|
+
tools: toolDefs,
|
|
522
556
|
});
|
|
523
557
|
|
|
524
558
|
case "tools/call": {
|
|
@@ -562,7 +596,11 @@ export function createAgentServer(
|
|
|
562
596
|
) {
|
|
563
597
|
switch (toolName) {
|
|
564
598
|
case "call_agent": {
|
|
565
|
-
|
|
599
|
+
// Validate + strip nulls (OpenAI convention: null = absent)
|
|
600
|
+
const parsed = callAgentValidate.safeParse(args);
|
|
601
|
+
const req = (parsed.success
|
|
602
|
+
? (parsed.data as Record<string, unknown>).request ?? parsed.data
|
|
603
|
+
: (args.request ?? args)) as CallAgentRequest;
|
|
566
604
|
|
|
567
605
|
// Inject auth context
|
|
568
606
|
if (auth) {
|
|
@@ -597,7 +635,7 @@ export function createAgentServer(
|
|
|
597
635
|
|
|
598
636
|
case "list_agents": {
|
|
599
637
|
const { query: listQuery, limit: listLimit, cursor: listCursor } =
|
|
600
|
-
|
|
638
|
+
listAgentsValidate.parse(args);
|
|
601
639
|
const agents = registry.list();
|
|
602
640
|
let visible = agents.filter((agent) => canSeeAgent(agent, auth));
|
|
603
641
|
|
package/src/validate.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const SerializedToolSchema = z.object({
|
|
|
22
22
|
inputSchema: z
|
|
23
23
|
.record(z.unknown())
|
|
24
24
|
.default({ type: "object", properties: {} }),
|
|
25
|
-
outputSchema: z.
|
|
25
|
+
outputSchema: z.object({}).passthrough().optional(),
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// ============================================
|
|
@@ -36,7 +36,7 @@ export const SerializedAgentDefinitionSchema = z
|
|
|
36
36
|
description: z.string().default(""),
|
|
37
37
|
version: z.string().default("1.0.0"),
|
|
38
38
|
visibility: z.enum(["public", "private"]).default("public"),
|
|
39
|
-
auth: z.
|
|
39
|
+
auth: z.object({}).passthrough().optional(),
|
|
40
40
|
serverSource: z.string().optional(),
|
|
41
41
|
serverInfo: z
|
|
42
42
|
.object({
|