@hasna/knowledge 0.2.2 → 0.2.3

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.
@@ -1,97 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
2
- import { mkdtempSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- import { Client } from '@modelcontextprotocol/sdk/client/index.js';
6
- import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
7
- import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
8
- import { buildServer } from '../src/mcp.js';
9
- import {
10
- DEFAULT_MCP_HTTP_PORT,
11
- isHttpMode,
12
- resolveMcpHttpPort,
13
- startMcpHttpServer,
14
- } from '../src/mcp-http.js';
15
-
16
- const storePath = join(mkdtempSync(join(tmpdir(), 'knowledge-mcp-http-')), 'db.json');
17
-
18
- describe('knowledge MCP HTTP transport', () => {
19
- test('defaults port to 8819', () => {
20
- expect(DEFAULT_MCP_HTTP_PORT).toBe(8819);
21
- expect(resolveMcpHttpPort(['node'], {})).toBe(8819);
22
- expect(resolveMcpHttpPort(['node', '--port', '9001'], {})).toBe(9001);
23
- expect(resolveMcpHttpPort(['node'], { MCP_HTTP_PORT: '9002' })).toBe(9002);
24
- });
25
-
26
- test('isHttpMode detects flag and env', () => {
27
- expect(isHttpMode(['node'], {})).toBe(false);
28
- expect(isHttpMode(['node', '--http'], {})).toBe(true);
29
- expect(isHttpMode(['node'], { MCP_HTTP: '1' })).toBe(true);
30
- });
31
- });
32
-
33
- describe('knowledge buildServer stdio registration', () => {
34
- test('registers tools over in-memory transport', async () => {
35
- const server = buildServer();
36
- const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
37
- await server.connect(serverTransport);
38
-
39
- const client = new Client({ name: 'test', version: '0.0.0' });
40
- await client.connect(clientTransport);
41
-
42
- const tools = await client.listTools();
43
- expect(tools.tools.some((tool) => tool.name === 'ok_stats')).toBe(true);
44
-
45
- await client.close();
46
- await server.close();
47
- });
48
- });
49
-
50
- describe('knowledge streamable HTTP server', () => {
51
- let handle: Awaited<ReturnType<typeof startMcpHttpServer>>;
52
-
53
- beforeAll(async () => {
54
- handle = await startMcpHttpServer(buildServer, { port: 0 });
55
- });
56
-
57
- afterAll(async () => {
58
- await handle.close();
59
- });
60
-
61
- test('GET /health returns ok', async () => {
62
- const res = await fetch(`http://${handle.host}:${handle.port}/health`);
63
- expect(res.status).toBe(200);
64
- expect(await res.json()).toEqual({ status: 'ok', name: 'knowledge' });
65
- });
66
-
67
- test('initialize and call ok_stats over streamable HTTP', async () => {
68
- const transport = new StreamableHTTPClientTransport(
69
- new URL(`http://${handle.host}:${handle.port}/mcp`),
70
- );
71
- const client = new Client({ name: 'test', version: '0.0.0' });
72
- await client.connect(transport);
73
-
74
- const result = await client.callTool({ name: 'ok_stats', arguments: { store_path: storePath } });
75
- expect(result.content).toBeDefined();
76
- expect(Array.isArray(result.content)).toBe(true);
77
-
78
- await client.close();
79
- });
80
-
81
- test('serves three concurrent clients from one process', async () => {
82
- const clients = await Promise.all(
83
- Array.from({ length: 3 }, async () => {
84
- const transport = new StreamableHTTPClientTransport(
85
- new URL(`http://${handle.host}:${handle.port}/mcp`),
86
- );
87
- const client = new Client({ name: 'test', version: '0.0.0' });
88
- await client.connect(transport);
89
- const tools = await client.listTools();
90
- return { client, count: tools.tools.length };
91
- }),
92
- );
93
-
94
- expect(clients.every((entry) => entry.count > 0)).toBe(true);
95
- await Promise.all(clients.map((entry) => entry.client.close()));
96
- });
97
- });
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ES2022",
5
- "moduleResolution": "bundler",
6
- "lib": ["ES2022"],
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": false,
10
- "skipLibCheck": true,
11
- "allowImportingExtensions": true,
12
- "noEmit": true
13
- },
14
- "include": ["src/**/*", "tests/**/*"],
15
- "exclude": ["node_modules", "dist", "bin"]
16
- }