Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@mcp-layer/schema

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mcp-layer/schema - npm Package Compare versions

Comparing version
1.0.3
to
1.0.4
+1
-1
package.json
{
"name": "@mcp-layer/schema",
"version": "1.0.3",
"version": "1.0.4",
"description": "Extract and normalize MCP schemas into a unified Zod-based format.",

@@ -5,0 +5,0 @@ "repository": {

@@ -33,3 +33,3 @@ # @mcp-layer/schema

import { connect } from '@mcp-layer/connect';
import { extract } from '@mcp-layer/schema';
import { composeCatalog, extract } from '@mcp-layer/schema';

@@ -43,2 +43,23 @@ const config = await load(undefined, process.cwd());

await session.close();
const catalog = composeCatalog({
server: {
info: { name: 'demo', version: '1.0.0' },
capabilities: { tools: {} },
instructions: 'Use the local catalog.',
},
tools: [{
name: 'echo',
description: 'Echo text.',
inputSchema: {
type: 'object',
properties: {
text: { type: 'string' },
},
required: ['text'],
},
}],
});
console.log(catalog.items[0]);
```

@@ -48,7 +69,8 @@

1) Reads the MCP server capabilities and metadata from the live client connection.
1) Reads the MCP server capabilities and metadata from the live client connection with `extract(session)`.
2) Calls MCP list endpoints (`tools/list`, `resources/list`, `resources/templates/list`, `prompts/list`) using pagination.
3) Normalizes everything into a unified, type-discriminated schema so generators can consume a single list.
4) Wraps tool input/output JSON Schemas into Zod validators backed by Ajv, while preserving the original JSON Schema.
5) Converts prompt arguments into a lightweight JSON Schema so prompts and tools share the same `detail.input` shape.
3) Composes the same normalized catalog shape from raw definitions with `composeCatalog(...)` when a live session is not available yet.
4) Normalizes everything into a unified, type-discriminated schema so generators can consume a single list.
5) Wraps tool input/output JSON Schemas into Zod validators backed by Ajv, while preserving the original JSON Schema.
6) Converts prompt arguments into a lightweight JSON Schema so prompts and tools share the same `detail.input` shape.

@@ -149,4 +171,5 @@ ## Output shape (authoritative)

- This package does not open or close connections. It expects a live `Session` from `@mcp-layer/connect` or `@mcp-layer/attach`.
- `extract(session)` does not open or close connections. It expects a live `Session` from `@mcp-layer/connect` or `@mcp-layer/attach`.
- You are responsible for calling `session.close()` after extraction.
- `composeCatalog(...)` is pure and does not require a connection.
- If the server doesn't advertise a capability (tools/resources/prompts), extraction skips that surface.

@@ -153,0 +176,0 @@

@@ -420,2 +420,41 @@ import Ajv from 'ajv';

/**
* Derive advertised capabilities from the provided raw MCP definition sets.
* @param {{ tools?: Array<Record<string, unknown>>, resources?: Array<Record<string, unknown>>, templates?: Array<Record<string, unknown>>, prompts?: Array<Record<string, unknown>> }} data - Raw MCP definition sets.
* @returns {Record<string, unknown> | undefined}
*/
function capabilities(data) {
const caps = {};
if (Array.isArray(data.tools)) caps.tools = {};
if (Array.isArray(data.resources) || Array.isArray(data.templates)) caps.resources = {};
if (Array.isArray(data.prompts)) caps.prompts = {};
return Object.keys(caps).length > 0 ? caps : undefined;
}
/**
* Compose a unified catalog from raw MCP definitions without a live session.
* This lets adapters bootstrap routes from already-known tool/resource shapes
* while keeping the output identical to `extract(session)`.
*
* @param {{ server?: { info?: Record<string, unknown>, capabilities?: Record<string, unknown>, instructions?: string }, tools?: Array<Record<string, unknown>>, resources?: Array<Record<string, unknown>>, templates?: Array<Record<string, unknown>>, prompts?: Array<Record<string, unknown>> }} input - Raw server metadata and MCP definitions.
* @returns {{ server: { info: Record<string, unknown> | undefined, capabilities: Record<string, unknown> | undefined, instructions: string | undefined }, items: Array<Record<string, unknown>> }}
*/
export function composeCatalog(input = {}) {
const server = isrecord(input.server) ? input.server : {};
const info = isrecord(server.info) ? server.info : undefined;
const caps = isrecord(server.capabilities) ? server.capabilities : capabilities(input);
const instructions = typeof server.instructions === 'string' ? server.instructions : undefined;
return {
server: {
info,
capabilities: caps,
instructions,
},
items: normalize(input),
};
}
/**
* Extract MCP tool/resource/prompt schemas into a unified Zod-backed format.

@@ -455,12 +494,10 @@ * @param {import('@mcp-layer/session').Session} link - Active session with a connected MCP server.

const items = normalize(data);
return {
return composeCatalog({
server: {
info,
capabilities: caps,
instructions
instructions,
},
items
};
...data,
});
}
/**
* Compose a unified catalog from raw MCP definitions without a live session.
* This lets adapters bootstrap routes from already-known tool/resource shapes
* while keeping the output identical to `extract(session)`.
*
* @param {{ server?: { info?: Record<string, unknown>, capabilities?: Record<string, unknown>, instructions?: string }, tools?: Array<Record<string, unknown>>, resources?: Array<Record<string, unknown>>, templates?: Array<Record<string, unknown>>, prompts?: Array<Record<string, unknown>> }} input - Raw server metadata and MCP definitions.
* @returns {{ server: { info: Record<string, unknown> | undefined, capabilities: Record<string, unknown> | undefined, instructions: string | undefined }, items: Array<Record<string, unknown>> }}
*/
export function composeCatalog(input?: {
server?: {
info?: Record<string, unknown>;
capabilities?: Record<string, unknown>;
instructions?: string;
};
tools?: Array<Record<string, unknown>>;
resources?: Array<Record<string, unknown>>;
templates?: Array<Record<string, unknown>>;
prompts?: Array<Record<string, unknown>>;
}): {
server: {
info: Record<string, unknown> | undefined;
capabilities: Record<string, unknown> | undefined;
instructions: string | undefined;
};
items: Array<Record<string, unknown>>;
};
/**
* Extract MCP tool/resource/prompt schemas into a unified Zod-backed format.

@@ -3,0 +29,0 @@ * @param {import('@mcp-layer/session').Session} link - Active session with a connected MCP server.