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:
32
src/mcp.js
Executable file
32
src/mcp.js
Executable 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);
|
||||
});
|
||||
Reference in New Issue
Block a user