ydc-mcp-server 1.6.1

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,93 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * OpenAI-Compatible HTTP Server for You.com Agents
5
+ * Provides a REST API that mimics OpenAI's chat completions endpoint
6
+ * Supports multi-user, multi-conversation sessions
7
+ */
8
+
9
+ import express from 'express';
10
+ import cors from 'cors';
11
+ import { createServer } from 'http';
12
+
13
+ // Import routes
14
+ import chatRoutes from './lib/routes/chat.js';
15
+ import modelsRoutes from './lib/routes/models.js';
16
+ import conversationsRoutes from './lib/routes/conversations.js';
17
+ import healthRoutes from './lib/routes/health.js';
18
+
19
+ // Import config
20
+ import { storeConfig } from './lib/conversation-store.js';
21
+ import { authConfig } from './lib/auth-middleware.js';
22
+ import { listAdvancedVersions, getDefaultAdvancedVersion } from './lib/advanced-versions.js';
23
+
24
+ const app = express();
25
+ const startPort = parseInt(process.env.YDC_OPENAI_PORT) || 3002;
26
+ const API_KEY = process.env.YDC_API_KEY;
27
+
28
+ // Function to find available port
29
+ async function findAvailablePort(startPort, maxAttempts = 10) {
30
+ for (let i = 0; i < maxAttempts; i++) {
31
+ const port = startPort + i;
32
+ try {
33
+ await new Promise((resolve, reject) => {
34
+ const server = createServer();
35
+ server.listen(port, () => {
36
+ server.close(() => resolve());
37
+ });
38
+ server.on('error', reject);
39
+ });
40
+ return port;
41
+ } catch (error) {
42
+ if (error.code !== 'EADDRINUSE') {
43
+ throw error;
44
+ }
45
+ }
46
+ }
47
+ throw new Error(`No available port found starting from ${startPort}`);
48
+ }
49
+
50
+ // Middleware
51
+ app.use(cors());
52
+ app.use(express.json());
53
+
54
+ // Routes
55
+ app.use(chatRoutes);
56
+ app.use(modelsRoutes);
57
+ app.use(conversationsRoutes);
58
+ app.use(healthRoutes);
59
+
60
+ // Start server with auto port detection
61
+ async function startServer() {
62
+ try {
63
+ const port = await findAvailablePort(startPort);
64
+ app.set('port', port);
65
+
66
+ app.listen(port, () => {
67
+ console.log(`šŸš€ You.com OpenAI-Compatible Server running on port ${port}`);
68
+ console.log(`šŸ“‹ Base URL: http://localhost:${port}`);
69
+ console.log(`šŸ”‘ YDC API Key configured: ${!!API_KEY}`);
70
+ console.log(`šŸ“¦ Conversation Store: ${storeConfig.STORE_TYPE}${storeConfig.STORE_TYPE === 'sqlite' && storeConfig.isDbConnected() ? ` (${storeConfig.DB_PATH})` : ''}`);
71
+ console.log(`šŸ” Token Auth: ${authConfig.REQUIRE_TOKEN_AUTH ? `enabled (${authConfig.ACCESS_TOKENS_COUNT} tokens)` : 'disabled (accept all)'}`);
72
+ console.log(`\nšŸ“– Endpoints:`);
73
+ console.log(` POST http://localhost:${port}/v1/chat/completions`);
74
+ console.log(` GET http://localhost:${port}/v1/models`);
75
+ console.log(` GET http://localhost:${port}/v1/versions`);
76
+ console.log(` GET http://localhost:${port}/health`);
77
+ console.log(` GET/POST/DELETE http://localhost:${port}/v1/conversations`);
78
+
79
+ try {
80
+ const versions = listAdvancedVersions();
81
+ const defaultVersion = getDefaultAdvancedVersion();
82
+ console.log(`\nšŸŽÆ Advanced Versions: ${versions.length} available (default: ${defaultVersion})`);
83
+ } catch (error) {
84
+ console.error('āŒ Error loading advanced versions:', error.message);
85
+ }
86
+ });
87
+ } catch (error) {
88
+ console.error('āŒ Failed to start server:', error.message);
89
+ process.exit(1);
90
+ }
91
+ }
92
+
93
+ startServer();
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "ydc-mcp-server",
3
+ "version": "1.6.1",
4
+ "description": "MCP server for You.com Agents API - Express, Research, Advanced agents with multi-turn conversations, streaming, and OpenAI compatibility",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "ydc-mcp-server": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "openai-server.js",
13
+ "lib/",
14
+ "README.md",
15
+ "README_ZH_TW.md",
16
+ "README_ZH_CN.md",
17
+ "README_JA.md"
18
+ ],
19
+ "scripts": {
20
+ "start": "node index.js",
21
+ "start:openai": "node openai-server.js",
22
+ "test": "node tests/test.js",
23
+ "test:api": "node tests/test-api.js",
24
+ "test:streaming": "node tests/test-streaming.js",
25
+ "test:mcp": "node tests/test-mcp-tools.js",
26
+ "load-test": "node tools/load-test.js",
27
+ "prepublishOnly": "echo 'Ready to publish'"
28
+ },
29
+ "dependencies": {
30
+ "@modelcontextprotocol/sdk": "^1.25.1"
31
+ },
32
+ "optionalDependencies": {
33
+ "better-sqlite3": "^11.7.0",
34
+ "chalk": "^5.6.2",
35
+ "cli-progress": "^3.12.0",
36
+ "cli-table3": "^0.6.5",
37
+ "cors": "^2.8.5",
38
+ "express": "^4.18.2",
39
+ "node-fetch": "^3.3.2"
40
+ },
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "keywords": [
45
+ "mcp",
46
+ "you.com",
47
+ "ydc",
48
+ "agents",
49
+ "ai",
50
+ "research",
51
+ "advanced",
52
+ "streaming",
53
+ "openai",
54
+ "chat",
55
+ "conversation"
56
+ ],
57
+ "author": "linuxdo-ref",
58
+ "license": "MIT",
59
+ "publishConfig": {
60
+ "access": "public"
61
+ }
62
+ }