tiny-stdio-mcp-server 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { createServer } from "./server.js";
2
- export type { MessageHandler, MessageSession, Server } from "./server.js";
2
+ export type { CustomMethodHandler, MessageHandler, MessageSession, MessageSessionContext, Server } from "./server.js";
3
3
  export { defineSchema } from "./schema.js";
4
4
  export type { TypedSchema } from "./schema.js";
5
5
  export { Image, Audio, File, toContentBlocks, fileTypeFromBuffer, DEFAULT_FROM_URL_MAX_BYTES, } from "./content/index.js";
package/dist/server.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface Server {
6
6
  prompt(definition: Prompt, handler: PromptHandler): Server;
7
7
  resource(definition: Resource, handler: ResourceHandler): Server;
8
8
  resourceTemplate(definition: ResourceTemplate, handler: ResourceHandler): Server;
9
+ method(name: string, handler: CustomMethodHandler): Server;
9
10
  onNotification(listener: (notification: JSONRPCNotification) => void): () => void;
10
11
  removeTool(name: string): boolean;
11
12
  removePrompt(name: string): boolean;
@@ -21,6 +22,11 @@ export interface Server {
21
22
  connect(transport: Transport): Promise<void>;
22
23
  connectSDK(transport: SDKTransport): Promise<void>;
23
24
  }
25
+ export interface MessageSessionContext {
26
+ readonly signal: AbortSignal;
27
+ notify(method: string, params?: Record<string, unknown>): Promise<void>;
28
+ }
29
+ export type CustomMethodHandler = (params: Record<string, unknown> | undefined, session: MessageSessionContext) => unknown | Promise<unknown>;
24
30
  export type MessageHandler = (method: string, params?: Record<string, unknown>) => Promise<HandleResult>;
25
31
  export interface MessageSession {
26
32
  handleMessage: MessageHandler;
package/dist/server.js CHANGED
@@ -20,13 +20,15 @@ export function createServer(options) {
20
20
  const prompts = new Map();
21
21
  const resources = new Map();
22
22
  const resourceTemplates = new Map();
23
+ const methods = new Map();
23
24
  const notificationListeners = new Set();
24
25
  const connectionNotificationListeners = new Map();
25
26
  const defaultLifecycle = {
26
27
  initialized: false,
27
28
  initializeAccepted: false,
28
29
  notificationReady: false,
29
- resourceSubscriptions: new Set()
30
+ resourceSubscriptions: new Set(),
31
+ abortController: new AbortController()
30
32
  };
31
33
  const messageLifecycles = new Set([defaultLifecycle]);
32
34
  const handleMessageWithLifecycle = async (method, lifecycle, params) => {
@@ -269,6 +271,28 @@ export function createServer(options) {
269
271
  }
270
272
  return { result: {} };
271
273
  }
274
+ const customMethod = methods.get(method);
275
+ if (customMethod !== undefined) {
276
+ try {
277
+ const result = await customMethod(params, {
278
+ signal: lifecycle.abortController.signal,
279
+ async notify(notificationMethod, notificationParams) {
280
+ if (!lifecycle.notificationReady || lifecycle.listener === undefined) {
281
+ return;
282
+ }
283
+ await lifecycle.listener({
284
+ jsonrpc: "2.0",
285
+ method: notificationMethod,
286
+ ...(notificationParams === undefined ? {} : { params: notificationParams })
287
+ });
288
+ }
289
+ });
290
+ return { result };
291
+ }
292
+ catch (error) {
293
+ return internalError(toErrorMessage(error));
294
+ }
295
+ }
272
296
  return {
273
297
  error: {
274
298
  code: JSON_RPC_ERROR_CODES.METHOD_NOT_FOUND,
@@ -281,7 +305,9 @@ export function createServer(options) {
281
305
  initialized: false,
282
306
  initializeAccepted: false,
283
307
  notificationReady: false,
284
- resourceSubscriptions: new Set()
308
+ resourceSubscriptions: new Set(),
309
+ abortController: new AbortController(),
310
+ listener
285
311
  };
286
312
  messageLifecycles.add(lifecycle);
287
313
  if (listener !== undefined) {
@@ -290,6 +316,7 @@ export function createServer(options) {
290
316
  return {
291
317
  handleMessage: (method, params) => handleMessageWithLifecycle(method, lifecycle, params),
292
318
  close: () => {
319
+ lifecycle.abortController.abort();
293
320
  if (listener !== undefined) {
294
321
  connectionNotificationListeners.delete(listener);
295
322
  }
@@ -411,6 +438,11 @@ export function createServer(options) {
411
438
  resourceTemplates.set(definition.uriTemplate, { ...definition, handler });
412
439
  return server;
413
440
  },
441
+ method(name, handler) {
442
+ assertNonEmptyName(name, "Method name required");
443
+ methods.set(name, handler);
444
+ return server;
445
+ },
414
446
  onNotification(listener) {
415
447
  notificationListeners.add(listener);
416
448
  return () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiny-stdio-mcp-server",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "bugs": {
5
5
  "url": "https://github.com/poe-platform/poe-code/issues"
6
6
  },