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.
- package/README.md +140 -0
- package/README_JA.md +138 -0
- package/README_ZH_CN.md +138 -0
- package/README_ZH_TW.md +138 -0
- package/index.js +604 -0
- package/lib/advanced-versions.js +113 -0
- package/lib/api-client.js +134 -0
- package/lib/auth-middleware.js +44 -0
- package/lib/conversation-store.js +271 -0
- package/lib/openai-mapper.js +215 -0
- package/lib/routes/chat.js +199 -0
- package/lib/routes/conversations.js +94 -0
- package/lib/routes/health.js +31 -0
- package/lib/routes/models.js +111 -0
- package/openai-server.js +93 -0
- package/package.json +62 -0
package/openai-server.js
ADDED
|
@@ -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
|
+
}
|