Skip to content

Commit 2e35b15

Browse files
committed
Merge branch 'main' into justin/simplified-api
2 parents 7629c70 + f8e5faf commit 2e35b15

File tree

7 files changed

+72
-8
lines changed

7 files changed

+72
-8
lines changed

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Model Context Protocol implementation for TypeScript",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",
@@ -19,21 +19,26 @@
1919
"mcp"
2020
],
2121
"exports": {
22-
"./*": "./dist/*"
22+
"./*": {
23+
"import": "./dist/esm/*",
24+
"require": "./dist/cjs/*"
25+
}
2326
},
2427
"typesVersions": {
2528
"*": {
2629
"*": [
27-
"./dist/*"
30+
"./dist/esm/*"
2831
]
2932
}
3033
},
3134
"files": [
3235
"dist"
3336
],
3437
"scripts": {
35-
"build": "tsc -p tsconfig.prod.json",
36-
"prepack": "tsc -p tsconfig.prod.json",
38+
"build": "npm run build:esm && npm run build:cjs",
39+
"build:esm": "tsc -p tsconfig.prod.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
40+
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
41+
"prepack": "npm run build:esm && npm run build:cjs",
3742
"lint": "eslint src/",
3843
"test": "jest",
3944
"start": "npm run server",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Server } from "../server/index.js";
2+
import { StdioServerTransport } from "../server/stdio.js";
3+
4+
describe("Process cleanup", () => {
5+
jest.setTimeout(5000); // 5 second timeout
6+
7+
it("should exit cleanly after closing transport", async () => {
8+
const server = new Server(
9+
{
10+
name: "test-server",
11+
version: "1.0.0",
12+
},
13+
{
14+
capabilities: {},
15+
}
16+
);
17+
18+
const transport = new StdioServerTransport();
19+
await server.connect(transport);
20+
21+
// Close the transport
22+
await transport.close();
23+
24+
// If we reach here without hanging, the test passes
25+
// The test runner will fail if the process hangs
26+
expect(true).toBe(true);
27+
});
28+
});

src/server/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test("should accept latest protocol version", async () => {
3838
name: "test server",
3939
version: "1.0",
4040
},
41+
instructions: "Test instructions",
4142
});
4243
sendPromiseResolve(undefined);
4344
}
@@ -57,6 +58,7 @@ test("should accept latest protocol version", async () => {
5758
tools: {},
5859
logging: {},
5960
},
61+
instructions: "Test instructions",
6062
},
6163
);
6264

src/server/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export type ServerOptions = ProtocolOptions & {
3434
* Capabilities to advertise as being supported by this server.
3535
*/
3636
capabilities?: ServerCapabilities;
37+
38+
/**
39+
* Optional instructions describing how to use the server and its features.
40+
*/
41+
instructions?: string;
3742
};
3843

3944
/**
@@ -73,6 +78,7 @@ export class Server<
7378
private _clientCapabilities?: ClientCapabilities;
7479
private _clientVersion?: Implementation;
7580
private _capabilities: ServerCapabilities;
81+
private _instructions?: string;
7682

7783
/**
7884
* Callback for when initialization has fully completed (i.e., the client has sent an `initialized` notification).
@@ -88,6 +94,7 @@ export class Server<
8894
) {
8995
super(options);
9096
this._capabilities = options?.capabilities ?? {};
97+
this._instructions = options?.instructions;
9198

9299
this.setRequestHandler(InitializeRequestSchema, (request) =>
93100
this._oninitialize(request),
@@ -250,6 +257,7 @@ export class Server<
250257
: LATEST_PROTOCOL_VERSION,
251258
capabilities: this.getCapabilities(),
252259
serverInfo: this._serverInfo,
260+
...(this._instructions && { instructions: this._instructions }),
253261
};
254262
}
255263

src/server/stdio.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,19 @@ export class StdioServerTransport implements Transport {
6262
}
6363

6464
async close(): Promise<void> {
65+
// Remove our event listeners first
6566
this._stdin.off("data", this._ondata);
6667
this._stdin.off("error", this._onerror);
68+
69+
// Check if we were the only data listener
70+
const remainingDataListeners = this._stdin.listenerCount('data');
71+
if (remainingDataListeners === 0) {
72+
// Only pause stdin if we were the only listener
73+
// This prevents interfering with other parts of the application that might be using stdin
74+
this._stdin.pause();
75+
}
76+
77+
// Clear the buffer and notify closure
6778
this._readBuffer.clear();
6879
this.onclose?.();
6980
}

tsconfig.cjs.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"outDir": "./dist/cjs"
7+
},
8+
"exclude": ["**/*.test.ts"]
9+
}

tsconfig.prod.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
3-
"exclude": [
4-
"**/*.test.ts",
5-
]
3+
"compilerOptions": {
4+
"outDir": "./dist/esm"
5+
},
6+
"exclude": ["**/*.test.ts"]
67
}

0 commit comments

Comments
 (0)