Closes #1005 A tool schema can be perfectly legal JSON Schema and still be rejected by the client the server is meant to run against — Go's `jsonschema` emits a bare `true` for `interface{}`, which the SDK accepts and Claude Code refuses with an opaque "Invalid input". The Inspector passed it through silently. Adds `core/json/schemaLint.ts`, a portability lint over a tool's inputSchema/outputSchema, and surfaces one shared verdict everywhere: the CLI's `--strict` report (exit 6 on an error-severity finding), the TUI's tool list marker + detail pane, and the web Tools sidebar flag + detail section. Deliberately not a JSON Schema validator: a census of 617 public servers found zero that fail the SDK's own parse, so a conformance check would report nothing on real servers. Each rule is instead a construct that is legal JSON Schema and known to be refused or mishandled by a shipping client — a bare boolean in a schema position, an array-form `type`, a remote `$ref`, a schema with no validation keyword, a non-object root. `test-servers/configs/unportable-schemas-http.json` exercises every rule, via a new `rawToolSchemas` override — the Zod-built presets cannot emit any of these shapes, which is the same reason a real server only hits this when its schemas come from another generator. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UL9retfvAXRgvi6EWk4SY4 Signed-off-by: cliffhall <cliff@futurescale.com>
120 lines
3.8 KiB
TypeScript
120 lines
3.8 KiB
TypeScript
/**
|
|
* Resolves config file preset refs to ServerConfig for createMcpServer
|
|
*/
|
|
|
|
import type { ServerConfig } from "./composable-test-server.js";
|
|
import type {
|
|
ToolDefinition,
|
|
TaskToolDefinition,
|
|
ResourceDefinition,
|
|
PromptDefinition,
|
|
ResourceTemplateDefinition,
|
|
} from "./composable-test-server.js";
|
|
import { createTestServerInfo } from "./test-server-fixtures.js";
|
|
import { resolvePreset } from "./preset-registry.js";
|
|
import type { ConfigFile, PresetRef } from "./load-config.js";
|
|
|
|
function mergeRequiredScopes<T extends { requiredScopes?: string[] }>(
|
|
item: T,
|
|
ref: PresetRef,
|
|
): T {
|
|
if (!ref.requiredScopes?.length) {
|
|
return item;
|
|
}
|
|
return { ...item, requiredScopes: ref.requiredScopes };
|
|
}
|
|
|
|
function resolvePresetRefs<T extends { requiredScopes?: string[] }>(
|
|
refs: Array<PresetRef | PresetRef[]> | undefined,
|
|
type: "tool" | "resource" | "resourceTemplate" | "prompt",
|
|
): T[] {
|
|
if (!refs || refs.length === 0) return [];
|
|
const result: Array<{ requiredScopes?: string[] }> = [];
|
|
for (const entry of refs) {
|
|
const items = Array.isArray(entry) ? entry : [entry];
|
|
for (const ref of items) {
|
|
const presetName = ref.preset;
|
|
if (!presetName || typeof presetName !== "string") {
|
|
throw new Error(
|
|
`Invalid preset ref: preset must be a non-empty string`,
|
|
);
|
|
}
|
|
const resolved = resolvePreset(type, presetName, ref.params);
|
|
const arr = Array.isArray(resolved) ? resolved : [resolved];
|
|
for (const item of arr) {
|
|
result.push(mergeRequiredScopes(item, ref));
|
|
}
|
|
}
|
|
}
|
|
// The caller pairs `type` with the matching `T`, so each resolved preset is
|
|
// the requested definition kind; TS can't see that correspondence.
|
|
return result as T[];
|
|
}
|
|
|
|
/**
|
|
* Resolve config file to ServerConfig for createMcpServer
|
|
*/
|
|
export function resolveConfig(config: ConfigFile): ServerConfig {
|
|
const tools = resolvePresetRefs<ToolDefinition | TaskToolDefinition>(
|
|
config.tools,
|
|
"tool",
|
|
);
|
|
const resources = resolvePresetRefs<ResourceDefinition>(
|
|
config.resources,
|
|
"resource",
|
|
);
|
|
const resourceTemplates = resolvePresetRefs<ResourceTemplateDefinition>(
|
|
config.resourceTemplates,
|
|
"resourceTemplate",
|
|
);
|
|
const prompts = resolvePresetRefs<PromptDefinition>(config.prompts, "prompt");
|
|
|
|
const serverInfo = createTestServerInfo(
|
|
config.serverInfo.name,
|
|
config.serverInfo.version,
|
|
);
|
|
|
|
const transport = config.transport;
|
|
const isHttp =
|
|
transport.type === "streamable-http" || transport.type === "sse";
|
|
|
|
const serverConfig: ServerConfig = {
|
|
serverInfo,
|
|
tools: tools.length > 0 ? tools : undefined,
|
|
resources: resources.length > 0 ? resources : undefined,
|
|
resourceTemplates:
|
|
resourceTemplates.length > 0 ? resourceTemplates : undefined,
|
|
prompts: prompts.length > 0 ? prompts : undefined,
|
|
logging: config.logging,
|
|
listChanged: config.listChanged,
|
|
subscriptions: config.subscriptions,
|
|
tasks: config.tasks,
|
|
tasksExtension: config.tasksExtension,
|
|
appElicitation: config.appElicitation,
|
|
maxPageSize: config.maxPageSize,
|
|
duplicateToolNames: config.duplicateToolNames,
|
|
rawToolSchemas: config.rawToolSchemas,
|
|
extensionGatedTools: config.extensionGatedTools,
|
|
serverType: isHttp
|
|
? (transport.type as "sse" | "streamable-http")
|
|
: undefined,
|
|
port: isHttp ? transport.port : undefined,
|
|
};
|
|
|
|
// Normalize the modern flag: `true` is shorthand for the default (dual-era
|
|
// stateless) posture; the object form passes through.
|
|
if (transport.modern !== undefined) {
|
|
serverConfig.modern =
|
|
transport.modern === true ? {} : transport.modern || undefined;
|
|
}
|
|
|
|
if (config.oauth) {
|
|
const { issuerUrl, ...oauthRest } = config.oauth;
|
|
serverConfig.oauth = {
|
|
...oauthRest,
|
|
...(issuerUrl && { issuerUrl: new URL(issuerUrl) }),
|
|
};
|
|
}
|
|
|
|
return serverConfig;
|
|
}
|