@mctx-ai/mcp-server 0.4.0 → 0.5.0

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
@@ -106,16 +106,33 @@ export interface Server {
106
106
  fetch(request: Request, env?: any, ctx?: any): Promise<Response>;
107
107
  }
108
108
 
109
+ /**
110
+ * Server configuration options.
111
+ */
112
+ export interface ServerOptions {
113
+ /**
114
+ * Instructions for LLM clients using this server.
115
+ * Helps guide the LLM on how to use the server's capabilities.
116
+ *
117
+ * @example
118
+ * "This server provides tools for managing customer data. Use list_customers to browse, get_customer to fetch details."
119
+ */
120
+ instructions?: string;
121
+ }
122
+
109
123
  /**
110
124
  * Creates an MCP server instance.
111
125
  *
126
+ * @param options - Server configuration options
112
127
  * @returns Server instance with registration methods and fetch handler
113
128
  *
114
129
  * @example
115
130
  * ```typescript
116
131
  * import { createServer, T } from '@mctx-ai/mcp-server';
117
132
  *
118
- * const server = createServer();
133
+ * const server = createServer({
134
+ * instructions: "You help developers debug CI pipelines..."
135
+ * });
119
136
  *
120
137
  * server.tool('greet', (args: { name: string }) => {
121
138
  * return `Hello, ${args.name}!`;
@@ -124,7 +141,7 @@ export interface Server {
124
141
  * export default { fetch: server.fetch };
125
142
  * ```
126
143
  */
127
- export function createServer(): Server;
144
+ export function createServer(options?: ServerOptions): Server;
128
145
 
129
146
  // ============================================================================
130
147
  // Handler Types
package/dist/server.js CHANGED
@@ -132,9 +132,13 @@ function paginate(items, cursor, pageSize = 50) {
132
132
 
133
133
  /**
134
134
  * Create MCP server instance
135
+ * @param {Object} [options] - Server configuration options
136
+ * @param {string} [options.instructions] - Server instructions for LLM clients
135
137
  * @returns {Object} Server app with registration methods and fetch handler
136
138
  */
137
- export function createServer() {
139
+ export function createServer(options = {}) {
140
+ const { instructions } = options;
141
+
138
142
  // Internal registries
139
143
  const tools = new Map();
140
144
  const resources = new Map();
@@ -678,6 +682,55 @@ export function createServer() {
678
682
  return {}; // Success
679
683
  }
680
684
 
685
+ /**
686
+ * Handle initialize request
687
+ * Auto-detects capabilities from registered tools/resources/prompts
688
+ * @param {Object} _params - Initialize params (clientInfo, etc.)
689
+ * @returns {Object} Server capabilities and info
690
+ */
691
+ function handleInitialize(_params) {
692
+ // Build capabilities object by detecting what's registered
693
+ const capabilities = {};
694
+
695
+ // Add tools capability if any tools are registered
696
+ if (tools.size > 0) {
697
+ capabilities.tools = {};
698
+ }
699
+
700
+ // Add resources capability if any resources are registered
701
+ if (resources.size > 0) {
702
+ capabilities.resources = {
703
+ subscribe: false, // Resource subscriptions not supported yet
704
+ listChanged: false, // Resource change notifications not supported yet
705
+ };
706
+ }
707
+
708
+ // Add prompts capability if any prompts are registered
709
+ if (prompts.size > 0) {
710
+ capabilities.prompts = {};
711
+ }
712
+
713
+ // Always include logging capability
714
+ capabilities.logging = {};
715
+
716
+ // Build response
717
+ const response = {
718
+ protocolVersion: "2024-11-05",
719
+ capabilities,
720
+ serverInfo: {
721
+ name: "@mctx-ai/mcp-server",
722
+ version: "0.3.0",
723
+ },
724
+ };
725
+
726
+ // Include instructions if provided
727
+ if (instructions) {
728
+ response.instructions = instructions;
729
+ }
730
+
731
+ return response;
732
+ }
733
+
681
734
  /**
682
735
  * Route JSON-RPC request to appropriate handler
683
736
  * @param {Object} request - JSON-RPC request
@@ -687,6 +740,17 @@ export function createServer() {
687
740
  const { method, params, _meta } = request;
688
741
 
689
742
  switch (method) {
743
+ case "initialize":
744
+ return handleInitialize(params);
745
+
746
+ case "initialized":
747
+ // Notification - no response needed
748
+ return null;
749
+
750
+ case "ping":
751
+ // Respond to ping with empty result
752
+ return {};
753
+
690
754
  case "tools/list":
691
755
  return handleToolsList(params);
692
756
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mctx-ai/mcp-server",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Build MCP servers with an Express-like API — no protocol knowledge required",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.d.ts CHANGED
@@ -106,16 +106,33 @@ export interface Server {
106
106
  fetch(request: Request, env?: any, ctx?: any): Promise<Response>;
107
107
  }
108
108
 
109
+ /**
110
+ * Server configuration options.
111
+ */
112
+ export interface ServerOptions {
113
+ /**
114
+ * Instructions for LLM clients using this server.
115
+ * Helps guide the LLM on how to use the server's capabilities.
116
+ *
117
+ * @example
118
+ * "This server provides tools for managing customer data. Use list_customers to browse, get_customer to fetch details."
119
+ */
120
+ instructions?: string;
121
+ }
122
+
109
123
  /**
110
124
  * Creates an MCP server instance.
111
125
  *
126
+ * @param options - Server configuration options
112
127
  * @returns Server instance with registration methods and fetch handler
113
128
  *
114
129
  * @example
115
130
  * ```typescript
116
131
  * import { createServer, T } from '@mctx-ai/mcp-server';
117
132
  *
118
- * const server = createServer();
133
+ * const server = createServer({
134
+ * instructions: "You help developers debug CI pipelines..."
135
+ * });
119
136
  *
120
137
  * server.tool('greet', (args: { name: string }) => {
121
138
  * return `Hello, ${args.name}!`;
@@ -124,7 +141,7 @@ export interface Server {
124
141
  * export default { fetch: server.fetch };
125
142
  * ```
126
143
  */
127
- export function createServer(): Server;
144
+ export function createServer(options?: ServerOptions): Server;
128
145
 
129
146
  // ============================================================================
130
147
  // Handler Types
package/src/server.js CHANGED
@@ -132,9 +132,13 @@ function paginate(items, cursor, pageSize = 50) {
132
132
 
133
133
  /**
134
134
  * Create MCP server instance
135
+ * @param {Object} [options] - Server configuration options
136
+ * @param {string} [options.instructions] - Server instructions for LLM clients
135
137
  * @returns {Object} Server app with registration methods and fetch handler
136
138
  */
137
- export function createServer() {
139
+ export function createServer(options = {}) {
140
+ const { instructions } = options;
141
+
138
142
  // Internal registries
139
143
  const tools = new Map();
140
144
  const resources = new Map();
@@ -678,6 +682,55 @@ export function createServer() {
678
682
  return {}; // Success
679
683
  }
680
684
 
685
+ /**
686
+ * Handle initialize request
687
+ * Auto-detects capabilities from registered tools/resources/prompts
688
+ * @param {Object} _params - Initialize params (clientInfo, etc.)
689
+ * @returns {Object} Server capabilities and info
690
+ */
691
+ function handleInitialize(_params) {
692
+ // Build capabilities object by detecting what's registered
693
+ const capabilities = {};
694
+
695
+ // Add tools capability if any tools are registered
696
+ if (tools.size > 0) {
697
+ capabilities.tools = {};
698
+ }
699
+
700
+ // Add resources capability if any resources are registered
701
+ if (resources.size > 0) {
702
+ capabilities.resources = {
703
+ subscribe: false, // Resource subscriptions not supported yet
704
+ listChanged: false, // Resource change notifications not supported yet
705
+ };
706
+ }
707
+
708
+ // Add prompts capability if any prompts are registered
709
+ if (prompts.size > 0) {
710
+ capabilities.prompts = {};
711
+ }
712
+
713
+ // Always include logging capability
714
+ capabilities.logging = {};
715
+
716
+ // Build response
717
+ const response = {
718
+ protocolVersion: "2024-11-05",
719
+ capabilities,
720
+ serverInfo: {
721
+ name: "@mctx-ai/mcp-server",
722
+ version: "0.3.0",
723
+ },
724
+ };
725
+
726
+ // Include instructions if provided
727
+ if (instructions) {
728
+ response.instructions = instructions;
729
+ }
730
+
731
+ return response;
732
+ }
733
+
681
734
  /**
682
735
  * Route JSON-RPC request to appropriate handler
683
736
  * @param {Object} request - JSON-RPC request
@@ -687,6 +740,17 @@ export function createServer() {
687
740
  const { method, params, _meta } = request;
688
741
 
689
742
  switch (method) {
743
+ case "initialize":
744
+ return handleInitialize(params);
745
+
746
+ case "initialized":
747
+ // Notification - no response needed
748
+ return null;
749
+
750
+ case "ping":
751
+ // Respond to ping with empty result
752
+ return {};
753
+
690
754
  case "tools/list":
691
755
  return handleToolsList(params);
692
756