New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@modelcontextprotocol/sdk

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@modelcontextprotocol/sdk - npm Package Compare versions

Comparing version 1.3.2 to 1.4.0

3

dist/cjs/cli.js

@@ -6,7 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const eventsource_1 = __importDefault(require("eventsource"));
const ws_1 = __importDefault(require("ws"));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
global.EventSource = eventsource_1.default;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
global.WebSocket = ws_1.default;

@@ -13,0 +10,0 @@ const express_1 = __importDefault(require("express"));

5

dist/cjs/client/index.d.ts

@@ -40,2 +40,3 @@ import { Protocol, ProtocolOptions, RequestOptions } from "../shared/protocol.js";

private _capabilities;
private _instructions?;
/**

@@ -61,2 +62,6 @@ * Initializes this client with the given name and version information.

getServerVersion(): Implementation | undefined;
/**
* After initialization has completed, this may be populated with information about the server's instructions.
*/
getInstructions(): string | undefined;
protected assertCapabilityForMethod(method: RequestT["method"]): void;

@@ -63,0 +68,0 @@ protected assertNotificationCapability(method: NotificationT["method"]): void;

@@ -77,2 +77,3 @@ "use strict";

this._serverVersion = result.serverInfo;
this._instructions = result.instructions;
await this.notification({

@@ -100,2 +101,8 @@ method: "notifications/initialized",

}
/**
* After initialization has completed, this may be populated with information about the server's instructions.
*/
getInstructions() {
return this._instructions;
}
assertCapabilityForMethod(method) {

@@ -102,0 +109,0 @@ var _a, _b, _c, _d, _e;

import { Transport } from "../shared/transport.js";
import { JSONRPCMessage } from "../types.js";
import { type EventSourceInit } from "eventsource";
/**
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
* messages and make separate POST requests for sending messages.
*
* This uses the EventSource API in browsers. You can install the `eventsource` package for Node.js.
*/

@@ -9,0 +8,0 @@ export declare class SSEClientTransport implements Transport {

@@ -5,7 +5,6 @@ "use strict";

const types_js_1 = require("../types.js");
const eventsource_1 = require("eventsource");
/**
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
* messages and make separate POST requests for sending messages.
*
* This uses the EventSource API in browsers. You can install the `eventsource` package for Node.js.
*/

@@ -23,3 +22,3 @@ class SSEClientTransport {

return new Promise((resolve, reject) => {
this._eventSource = new EventSource(this._url.href, this._eventSourceInit);
this._eventSource = new eventsource_1.EventSource(this._url.href, this._eventSourceInit);
this._abortController = new AbortController();

@@ -86,3 +85,3 @@ this._eventSource.onerror = (event) => {

body: JSON.stringify(message),
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal,
};

@@ -89,0 +88,0 @@ const response = await fetch(this._endpoint, init);

@@ -276,2 +276,8 @@ "use strict";

serverInfo: exports.ImplementationSchema,
/**
* Instructions describing how to use the server and its features.
*
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
*/
instructions: zod_1.z.optional(zod_1.z.string()),
});

@@ -278,0 +284,0 @@ /**

@@ -1,6 +0,3 @@

import EventSource from "eventsource";
import WebSocket from "ws";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
global.EventSource = EventSource;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
global.WebSocket = WebSocket;

@@ -7,0 +4,0 @@ import express from "express";

@@ -40,2 +40,3 @@ import { Protocol, ProtocolOptions, RequestOptions } from "../shared/protocol.js";

private _capabilities;
private _instructions?;
/**

@@ -61,2 +62,6 @@ * Initializes this client with the given name and version information.

getServerVersion(): Implementation | undefined;
/**
* After initialization has completed, this may be populated with information about the server's instructions.
*/
getInstructions(): string | undefined;
protected assertCapabilityForMethod(method: RequestT["method"]): void;

@@ -63,0 +68,0 @@ protected assertNotificationCapability(method: NotificationT["method"]): void;

@@ -74,2 +74,3 @@ import { mergeCapabilities, Protocol, } from "../shared/protocol.js";

this._serverVersion = result.serverInfo;
this._instructions = result.instructions;
await this.notification({

@@ -97,2 +98,8 @@ method: "notifications/initialized",

}
/**
* After initialization has completed, this may be populated with information about the server's instructions.
*/
getInstructions() {
return this._instructions;
}
assertCapabilityForMethod(method) {

@@ -99,0 +106,0 @@ var _a, _b, _c, _d, _e;

import { Transport } from "../shared/transport.js";
import { JSONRPCMessage } from "../types.js";
import { type EventSourceInit } from "eventsource";
/**
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
* messages and make separate POST requests for sending messages.
*
* This uses the EventSource API in browsers. You can install the `eventsource` package for Node.js.
*/

@@ -9,0 +8,0 @@ export declare class SSEClientTransport implements Transport {

import { JSONRPCMessageSchema } from "../types.js";
import { EventSource } from "eventsource";
/**
* Client transport for SSE: this will connect to a server using Server-Sent Events for receiving
* messages and make separate POST requests for sending messages.
*
* This uses the EventSource API in browsers. You can install the `eventsource` package for Node.js.
*/

@@ -81,3 +80,3 @@ export class SSEClientTransport {

body: JSON.stringify(message),
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal
signal: (_b = this._abortController) === null || _b === void 0 ? void 0 : _b.signal,
};

@@ -84,0 +83,0 @@ const response = await fetch(this._endpoint, init);

@@ -272,2 +272,8 @@ import { z } from "zod";

serverInfo: ImplementationSchema,
/**
* Instructions describing how to use the server and its features.
*
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
*/
instructions: z.optional(z.string()),
});

@@ -274,0 +280,0 @@ /**

{
"name": "@modelcontextprotocol/sdk",
"version": "1.3.2",
"version": "1.4.0",
"description": "Model Context Protocol implementation for TypeScript",

@@ -50,2 +50,3 @@ "license": "MIT",

"content-type": "^1.0.5",
"eventsource": "^3.0.2",
"raw-body": "^3.0.0",

@@ -65,3 +66,2 @@ "zod": "^3.23.8",

"eslint": "^9.8.0",
"eventsource": "^2.0.2",
"express": "^4.19.2",

@@ -68,0 +68,0 @@ "jest": "^29.7.0",

@@ -14,5 +14,5 @@ # MCP TypeScript SDK ![NPM Version](https://img.shields.io/npm/v/%40modelcontextprotocol%2Fsdk) ![MIT licensed](https://img.shields.io/npm/l/%40modelcontextprotocol%2Fsdk)

- [Running Your Server](#running-your-server)
- [Development Mode](#development-mode)
- [Claude Desktop Integration](#claude-desktop-integration)
- [Direct Execution](#direct-execution)
- [stdio](#stdio)
- [HTTP with SSE](#http-with-sse)
- [Testing and Debugging](#testing-and-debugging)
- [Examples](#examples)

@@ -47,2 +47,3 @@ - [Echo Server](#echo-server)

import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

@@ -75,2 +76,6 @@

);
// Start receiving messages on stdin and sending messages on stdout
const transport = new StdioServerTransport();
await server.connect(transport);
```

@@ -184,2 +189,62 @@

## Running Your Server
MCP servers in TypeScript need to be connected to a transport to communicate with clients. How you start the server depends on the choice of transport:
### stdio
For command-line tools and direct integrations:
```typescript
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({
name: "example-server",
version: "1.0.0"
});
// ... set up server resources, tools, and prompts ...
const transport = new StdioServerTransport();
await server.connect(transport);
```
### HTTP with SSE
For remote servers, start a web server with a Server-Sent Events (SSE) endpoint, and a separate endpoint for the client to send its messages to:
```typescript
import express from "express";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
const server = new McpServer({
name: "example-server",
version: "1.0.0"
});
// ... set up server resources, tools, and prompts ...
const app = express();
app.get("/mcp", async (req, res) => {
const transport = new SSEServerTransport("/messages", res);
await server.connect(transport);
});
app.post("/messages", async (req, res) => {
// Note: to support multiple simultaneous connections, these messages will
// need to be routed to a specific matching transport. (This logic isn't
// implemented here, for simplicity.)
await transport.handlePostMessage(req, res);
});
app.listen(3000);
```
### Testing and Debugging
To test your server, you can use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector). See its README for more information.
## Examples

@@ -186,0 +251,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc