@theyahia/mcp-core 1.0.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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Shared E2E smoke test utilities for MCP servers.
3
+ *
4
+ * Uses StdioClientTransport from the MCP SDK to connect to a compiled
5
+ * server binary and verify it starts, lists tools, and has quality descriptions.
6
+ */
7
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
9
+ /**
10
+ * Runs a smoke test against a compiled MCP server.
11
+ *
12
+ * 1. Spawns the server via StdioClientTransport
13
+ * 2. Connects and sends initialize
14
+ * 3. Lists tools and validates descriptions
15
+ * 4. Closes cleanly
16
+ */
17
+ export async function runSmokeTest(config) {
18
+ const errors = [];
19
+ const timeout = config.timeout ?? 10_000;
20
+ const transport = new StdioClientTransport({
21
+ command: "node",
22
+ args: [config.serverPath],
23
+ env: {
24
+ ...process.env,
25
+ ...config.env,
26
+ },
27
+ });
28
+ const client = new Client({
29
+ name: "smoke-test",
30
+ version: "1.0.0",
31
+ });
32
+ try {
33
+ // Connect with timeout
34
+ await Promise.race([
35
+ client.connect(transport),
36
+ new Promise((_, reject) => setTimeout(() => reject(new Error("Connection timeout")), timeout)),
37
+ ]);
38
+ const { tools } = await client.listTools();
39
+ if (tools.length < config.expectedToolCount) {
40
+ errors.push(`Expected at least ${config.expectedToolCount} tools, got ${tools.length}`);
41
+ }
42
+ const toolResults = tools.map((tool) => {
43
+ const desc = tool.description ?? "";
44
+ if (desc.length < 20) {
45
+ errors.push(`Tool "${tool.name}" has short description (${desc.length} chars). Minimum recommended: 20.`);
46
+ }
47
+ return {
48
+ name: tool.name,
49
+ description: desc,
50
+ descriptionLength: desc.length,
51
+ hasInputSchema: !!tool.inputSchema,
52
+ };
53
+ });
54
+ await client.close();
55
+ return {
56
+ connected: true,
57
+ toolCount: tools.length,
58
+ tools: toolResults,
59
+ errors,
60
+ };
61
+ }
62
+ catch (error) {
63
+ try {
64
+ await client.close();
65
+ }
66
+ catch {
67
+ // ignore close errors
68
+ }
69
+ return {
70
+ connected: false,
71
+ toolCount: 0,
72
+ tools: [],
73
+ errors: [
74
+ error instanceof Error ? error.message : String(error),
75
+ ],
76
+ };
77
+ }
78
+ }
79
+ //# sourceMappingURL=smoke.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoke.js","sourceRoot":"","sources":["../../src/testing/smoke.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAyBjF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAuB;IAEvB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC;IAEzC,MAAM,SAAS,GAAG,IAAI,oBAAoB,CAAC;QACzC,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC;QACzB,GAAG,EAAE;YACH,GAAG,OAAO,CAAC,GAAG;YACd,GAAG,MAAM,CAAC,GAAG;SACY;KAC5B,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,uBAAuB;QACvB,MAAM,OAAO,CAAC,IAAI,CAAC;YACjB,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;YACzB,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CACxB,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,EAAE,OAAO,CAAC,CACnE;SACF,CAAC,C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AAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aACvD;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@theyahia/mcp-core",
3
+ "version": "1.0.0",
4
+ "description": "Shared core library for @theyahia MCP servers — client, auth, errors, formatting, logging, CLI, server factory",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./errors": {
14
+ "types": "./dist/errors.d.ts",
15
+ "default": "./dist/errors.js"
16
+ },
17
+ "./format": {
18
+ "types": "./dist/format.d.ts",
19
+ "default": "./dist/format.js"
20
+ },
21
+ "./logging": {
22
+ "types": "./dist/logging.d.ts",
23
+ "default": "./dist/logging.js"
24
+ },
25
+ "./client": {
26
+ "types": "./dist/client.d.ts",
27
+ "default": "./dist/client.js"
28
+ },
29
+ "./server": {
30
+ "types": "./dist/server.d.ts",
31
+ "default": "./dist/server.js"
32
+ },
33
+ "./auth": {
34
+ "types": "./dist/auth/index.d.ts",
35
+ "default": "./dist/auth/index.js"
36
+ },
37
+ "./testing/smoke": {
38
+ "types": "./dist/testing/smoke.d.ts",
39
+ "default": "./dist/testing/smoke.js"
40
+ },
41
+ "./testing/smoke.js": {
42
+ "types": "./dist/testing/smoke.d.ts",
43
+ "default": "./dist/testing/smoke.js"
44
+ }
45
+ },
46
+ "files": [
47
+ "dist"
48
+ ],
49
+ "engines": {
50
+ "node": ">=18.0.0"
51
+ },
52
+ "dependencies": {
53
+ "@modelcontextprotocol/sdk": "^1.12.1",
54
+ "zod": "^3.24.4"
55
+ },
56
+ "optionalDependencies": {
57
+ "express": "^5.2.1"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^22.15.3",
61
+ "typescript": "^5.8.3",
62
+ "vitest": "^4.1.2"
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "license": "MIT",
68
+ "repository": {
69
+ "type": "git",
70
+ "url": "https://github.com/theYahia/mcp-servers.git",
71
+ "directory": "packages/core"
72
+ },
73
+ "author": "theYahia (https://github.com/theYahia)",
74
+ "scripts": {
75
+ "build": "tsc",
76
+ "dev": "tsc --watch",
77
+ "clean": "rm -rf dist .tsbuildinfo",
78
+ "typecheck": "tsc --noEmit",
79
+ "test": "vitest run",
80
+ "test:watch": "vitest"
81
+ }
82
+ }