Add MCP server for AI agents

Expose webshare_search, webshare_get_link, and webshare_login_check over
stdio via the Model Context Protocol SDK. Document client configuration.
This commit is contained in:
2026-08-07 08:50:10 +02:00
parent c2b5563c25
commit f7f1481a39
7 changed files with 929 additions and 20 deletions

32
src/mcp.js Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env node
/**
* MCP stdio entrypoint for AI agents.
*
* Configure clients with:
* command: node
* args: ["…/webshare-api/src/mcp.js"]
* env: { WEBSHARE_USERNAME, WEBSHARE_PASSWORD }
*
* Do not write application logs to stdout — it is reserved for the MCP protocol.
*/
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
const { createWebshareMcpServer } = require('./mcp-server');
async function main() {
const username = process.env.WEBSHARE_USERNAME;
const password = process.env.WEBSHARE_PASSWORD;
if (!username || !password) {
console.error('WEBSHARE_USERNAME and WEBSHARE_PASSWORD must be set');
process.exit(1);
}
const server = createWebshareMcpServer({ username, password });
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('webshare-api MCP server running on stdio');
}
main().catch((err) => {
console.error('MCP server failed:', err);
process.exit(1);
});