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.0
to
1.0.1
+2
-2
package.json
{
"name": "@mcp-layer/schema",
"version": "1.0.0",
"version": "1.0.1",
"description": "Extract and normalize MCP schemas into a unified Zod-based format.",

@@ -38,3 +38,3 @@ "repository": {

"devDependencies": {
"@mcp-layer/attach": "1.0.0",
"@mcp-layer/attach": "1.1.0",
"@mcp-layer/config": "1.0.0",

@@ -41,0 +41,0 @@ "@mcp-layer/connect": "1.0.0",

@@ -141,2 +141,3 @@ # @mcp-layer/schema

- Servers that return empty lists produce an empty `items` array (not an error).
- Servers that support resources but not resource templates are treated as having zero templates.

@@ -143,0 +144,0 @@ ## JSON Schema vs Zod

@@ -8,3 +8,3 @@ import Ajv from 'ajv';

* Test if a value is a plain object.
* @param {unknown} value
* @param {unknown} value - Value to test for plain object shape.
* @returns {value is Record<string, unknown>}

@@ -17,5 +17,22 @@ */

/**
* Determine whether an MCP error indicates a missing method.
* @param {unknown} error - Error value to inspect.
* @returns {boolean}
*/
function ismissing(error) {
if (!error || typeof error !== 'object') {
return false;
}
const code = 'code' in error ? error.code : undefined;
if (code === -32601) {
return true;
}
const message = 'message' in error ? String(error.message) : '';
return message.includes('Method') && message.includes('not found');
}
/**
* Build a Zod refinement function backed by Ajv.
* @param {import('ajv').Ajv} validator
* @param {import('ajv').ValidateFunction} check
* @param {import('ajv').Ajv} validator - Ajv instance used to format errors.
* @param {import('ajv').ValidateFunction} check - Compiled Ajv validation function.
* @returns {(value: unknown, ctx: import('zod').RefinementCtx) => void}

@@ -26,4 +43,4 @@ */

* Validate the value and emit Zod issues for Ajv failures.
* @param {unknown} value
* @param {import('zod').RefinementCtx} ctx
* @param {unknown} value - Value to validate.
* @param {import('zod').RefinementCtx} ctx - Zod refinement context for reporting issues.
* @returns {void}

@@ -45,3 +62,3 @@ */

* Wrap a JSON Schema into a Zod schema that delegates validation to Ajv.
* @param {unknown} json
* @param {unknown} json - JSON Schema definition to wrap.
* @returns {{ schema: import('zod').ZodTypeAny, json: Record<string, unknown> | undefined, error?: string }}

@@ -67,4 +84,4 @@ */

* @template T
* @param {(cursor?: string) => Promise<T & { nextCursor?: string }>} call
* @param {(result: T) => Array<unknown>} pull
* @param {(cursor?: string) => Promise<T & { nextCursor?: string }>} call - Function that requests a page by cursor.
* @param {(result: T) => Array<unknown>} pull - Function that extracts items from each page result.
* @returns {Promise<Array<unknown>>}

@@ -93,3 +110,3 @@ */

* Extract tool entries from a client.
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client - MCP client instance.
* @returns {Promise<Array<Record<string, unknown>>>}

@@ -100,3 +117,3 @@ */

* Fetch a page of tools.
* @param {string | undefined} cursor
* @param {string | undefined} cursor - Pagination cursor from the previous page.
* @returns {Promise<{ tools: Array<Record<string, unknown>>, nextCursor?: string }>}

@@ -113,3 +130,3 @@ */

* Pluck tool definitions from a list response.
* @param {{ tools?: Array<Record<string, unknown>> }} result
* @param {{ tools?: Array<Record<string, unknown>> }} result - listTools response payload.
* @returns {Array<Record<string, unknown>>}

@@ -126,3 +143,3 @@ */

* Extract resource entries from a client.
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client - MCP client instance.
* @returns {Promise<Array<Record<string, unknown>>>}

@@ -133,3 +150,3 @@ */

* Fetch a page of resources.
* @param {string | undefined} cursor
* @param {string | undefined} cursor - Pagination cursor from the previous page.
* @returns {Promise<{ resources: Array<Record<string, unknown>>, nextCursor?: string }>}

@@ -146,3 +163,3 @@ */

* Pluck resource definitions from a list response.
* @param {{ resources?: Array<Record<string, unknown>> }} result
* @param {{ resources?: Array<Record<string, unknown>> }} result - listResources response payload.
* @returns {Array<Record<string, unknown>>}

@@ -159,3 +176,3 @@ */

* Extract resource template entries from a client.
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client - MCP client instance.
* @returns {Promise<Array<Record<string, unknown>>>}

@@ -166,3 +183,3 @@ */

* Fetch a page of resource templates.
* @param {string | undefined} cursor
* @param {string | undefined} cursor - Pagination cursor from the previous page.
* @returns {Promise<{ resourceTemplates: Array<Record<string, unknown>>, nextCursor?: string }>}

@@ -179,3 +196,3 @@ */

* Pluck resource template definitions from a list response.
* @param {{ resourceTemplates?: Array<Record<string, unknown>> }} result
* @param {{ resourceTemplates?: Array<Record<string, unknown>> }} result - listResourceTemplates response payload.
* @returns {Array<Record<string, unknown>>}

@@ -187,3 +204,10 @@ */

return page(call, pull);
try {
return await page(call, pull);
} catch (error) {
if (ismissing(error)) {
return [];
}
throw error;
}
}

@@ -193,3 +217,3 @@

* Extract prompt entries from a client.
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client
* @param {import('@modelcontextprotocol/sdk/client/index.js').Client} client - MCP client instance.
* @returns {Promise<Array<Record<string, unknown>>>}

@@ -200,3 +224,3 @@ */

* Fetch a page of prompts.
* @param {string | undefined} cursor
* @param {string | undefined} cursor - Pagination cursor from the previous page.
* @returns {Promise<{ prompts: Array<Record<string, unknown>>, nextCursor?: string }>}

@@ -213,3 +237,3 @@ */

* Pluck prompt definitions from a list response.
* @param {{ prompts?: Array<Record<string, unknown>> }} result
* @param {{ prompts?: Array<Record<string, unknown>> }} result - listPrompts response payload.
* @returns {Array<Record<string, unknown>>}

@@ -226,3 +250,3 @@ */

* Build shared metadata from an MCP item.
* @param {Record<string, unknown>} item
* @param {Record<string, unknown>} item - MCP definition object.
* @returns {Record<string, unknown>}

@@ -243,3 +267,3 @@ */

* Build metadata for tools, including annotations.
* @param {Record<string, unknown>} tool
* @param {Record<string, unknown>} tool - Tool definition object.
* @returns {Record<string, unknown>}

@@ -257,3 +281,3 @@ */

* Derive a display title with tool annotation fallback.
* @param {Record<string, unknown>} tool
* @param {Record<string, unknown>} tool - Tool definition object.
* @returns {string | undefined}

@@ -273,3 +297,3 @@ */

* Extract MCP Apps UI metadata from an item.
* @param {Record<string, unknown>} item
* @param {Record<string, unknown>} item - MCP definition object.
* @returns {Record<string, unknown> | undefined}

@@ -303,3 +327,3 @@ */

* Normalize a tool definition into the unified schema.
* @param {Record<string, unknown>} tool
* @param {Record<string, unknown>} tool - Raw tool definition from MCP.
* @returns {Record<string, unknown>}

@@ -332,3 +356,3 @@ */

* Normalize a resource definition into the unified schema.
* @param {Record<string, unknown>} resource
* @param {Record<string, unknown>} resource - Raw resource definition from MCP.
* @returns {Record<string, unknown>}

@@ -355,3 +379,3 @@ */

* Normalize a resource template definition into the unified schema.
* @param {Record<string, unknown>} template
* @param {Record<string, unknown>} template - Raw resource template definition from MCP.
* @returns {Record<string, unknown>}

@@ -375,3 +399,3 @@ */

* Build a JSON schema from prompt arguments so prompts share the input schema shape.
* @param {Record<string, unknown>} prompt
* @param {Record<string, unknown>} prompt - Raw prompt definition from MCP.
* @returns {{ schema: import('zod').ZodTypeAny, json: Record<string, unknown> | undefined, error?: string }}

@@ -414,3 +438,3 @@ */

* Normalize a prompt definition into the unified schema.
* @param {Record<string, unknown>} prompt
* @param {Record<string, unknown>} prompt - Raw prompt definition from MCP.
* @returns {Record<string, unknown>}

@@ -434,3 +458,3 @@ */

* Convert a set of MCP definitions into a unified item list.
* @param {{ tools?: Array<Record<string, unknown>>, resources?: Array<Record<string, unknown>>, templates?: Array<Record<string, unknown>>, prompts?: Array<Record<string, unknown>> }} data
* @param {{ tools?: Array<Record<string, unknown>>, resources?: Array<Record<string, unknown>>, templates?: Array<Record<string, unknown>>, prompts?: Array<Record<string, unknown>> }} data - Aggregated MCP list responses.
* @returns {Array<Record<string, unknown>>}

@@ -470,3 +494,3 @@ */

* Extract MCP tool/resource/prompt schemas into a unified Zod-backed format.
* @param {import('@mcp-layer/session').Session} link
* @param {import('@mcp-layer/session').Session} link - Active session with a connected MCP server.
* @returns {Promise<{ server: { info: Record<string, unknown> | undefined, capabilities: Record<string, unknown> | undefined, instructions: string | undefined }, items: Array<Record<string, unknown>> }>}

@@ -473,0 +497,0 @@ */