iflow-mcp-rust-docs 1.0.0

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 ADDED
@@ -0,0 +1,101 @@
1
+ # MCP Rust Documentation Server
2
+
3
+ This is a Model Context Protocol (MCP) server that fetches and returns documentation for Rust crates providing essential context for LLM's when working with Rust code.
4
+
5
+ ## Features
6
+
7
+ - Fetches documentation for any Rust crate available on docs.rs
8
+ - Strips HTML and formats the content for readability
9
+ - Limits response size to prevent overwhelming the client
10
+ - Uses the latest MCP SDK (v1.6.1)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ # Clone the repository
16
+ git https://github.com/0xKoda/mcp-rust-docs.git
17
+ cd mcp-rust-docs
18
+
19
+ # Install dependencies
20
+ npm install
21
+ ```
22
+
23
+ ### Prerequisites
24
+
25
+ - Node.js
26
+ - npm
27
+
28
+ ## Usage
29
+
30
+ ```bash
31
+ # Start the server directly
32
+ npm start
33
+ ```
34
+
35
+ ## Integrating with AI Assistants
36
+
37
+ ### Claude Desktop
38
+
39
+ Add the following to your Claude Desktop configuration file (`claude_desktop_config.json`):
40
+
41
+ ```json
42
+ {
43
+ "mcpServers": {
44
+ "rust-docs": {
45
+ "command": "node",
46
+ "args": ["/absolute/path/to/index.js"]
47
+ }
48
+ }
49
+ }
50
+ ```
51
+
52
+ Replace `/absolute/path/to/index.js` with the absolute path to the index.js file in this repository.
53
+
54
+ ## Example Usage
55
+
56
+ Once the server is running and configured with your AI assistant, you can ask questions like:
57
+
58
+ - "Look up the documentation for the 'tokio' crate"
59
+ - "What features does the 'serde' crate provide?"
60
+ - "Show me the documentation for 'ratatui'"
61
+ - "Can you explain the main modules in the 'axum' crate?"
62
+
63
+ The AI will use the `lookup_crate_docs` tool to fetch and display the relevant documentation.
64
+
65
+ ## Testing with MCP Inspector
66
+
67
+ You can test this server using the MCP Inspector:
68
+
69
+ ```bash
70
+ npx @modelcontextprotocol/inspector
71
+ ```
72
+
73
+ Then select the "Connect to a local server" option and follow the prompts.
74
+
75
+ ## How It Works
76
+
77
+ This server implements a single MCP tool called `lookup_crate_docs` that:
78
+
79
+ 1. Takes a Rust crate name as input (optional, defaults to 'tokio' if not provided)
80
+ 2. Fetches the documentation from docs.rs
81
+ 3. Converts the HTML to plain text using the html-to-text library
82
+ 4. Truncates the content if it exceeds 8000 characters
83
+ 5. Returns the formatted documentation in the proper MCP response format
84
+
85
+ ## SDK Implementation Notes
86
+
87
+ This server uses the MCP SDK with carefully structured import paths. If you're modifying the code, be aware that:
88
+
89
+ 1. The SDK requires importing from specific paths (e.g., `@modelcontextprotocol/sdk/server/mcp.js`)
90
+ 2. We use the high-level McpServer API rather than the low-level tools
91
+ 3. The tool definition uses Zod for parameter validation
92
+ 4. Console output is redirected to stderr to avoid breaking the MCP protocol
93
+ 5. The tool returns properly formatted MCP response objects
94
+
95
+ ## Contributing
96
+
97
+ Contributions are welcome! Please feel free to submit a Pull Request.
98
+
99
+ ## License
100
+
101
+ MIT
package/index.js ADDED
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ // index.js - Plain JavaScript version
3
+ const axios = require('axios');
4
+ const { convert: htmlToText } = require('html-to-text');
5
+
6
+ // Import specific modules from the SDK with corrected paths
7
+ const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js');
8
+ const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
9
+ const { z } = require('zod');
10
+
11
+ // Redirect console.log to stderr to avoid breaking the MCP protocol
12
+ const originalConsoleLog = console.log;
13
+ console.log = function() {
14
+ console.error.apply(console, arguments);
15
+ };
16
+
17
+ // Initialize the MCP server
18
+ const server = new McpServer({
19
+ name: 'rust-docs',
20
+ version: '1.0.0'
21
+ });
22
+
23
+ // Define tool with proper Zod schema for parameters
24
+ server.tool(
25
+ 'lookup_crate_docs',
26
+ 'Lookup documentation for a Rust crate from docs.rs',
27
+ { crateName: z.string().optional().describe('Name of the Rust crate to lookup documentation for') },
28
+ async (args) => {
29
+ try {
30
+ // Extract crateName from args or use default
31
+ const crateName = args.crateName || "tokio";
32
+
33
+ console.error(`Fetching documentation for default crate: ${crateName}`);
34
+
35
+ // Construct the docs.rs URL for the crate
36
+ const url = `https://docs.rs/${crateName}/latest/${crateName}/index.html`;
37
+ console.error(`Making request to: ${url}`);
38
+
39
+ // Fetch the HTML content
40
+ const response = await axios.get(url);
41
+ console.error(`Received response with status: ${response.status}`);
42
+
43
+ // Convert HTML to text
44
+ const text = htmlToText(response.data, {
45
+ wordwrap: 130,
46
+ selectors: [
47
+ { selector: 'a', options: { ignoreHref: true } },
48
+ { selector: 'img', format: 'skip' }
49
+ ]
50
+ });
51
+
52
+ // Truncate if necessary
53
+ const maxLength = 8000;
54
+ const truncatedText = text.length > maxLength
55
+ ? text.substring(0, maxLength) + `\n\n[Content truncated. Full documentation available at ${url}]`
56
+ : text;
57
+
58
+ console.error(`Successfully processed docs for ${crateName}`);
59
+ return {
60
+ content: [{ type: "text", text: truncatedText }]
61
+ };
62
+ } catch (error) {
63
+ console.error(`Error fetching documentation:`, error.message);
64
+ return {
65
+ content: [{ type: "text", text: `Error: Could not fetch documentation. ${error.message}` }],
66
+ isError: true
67
+ };
68
+ }
69
+ }
70
+ );
71
+
72
+ // Define prompts for tools
73
+ server.prompt(
74
+ 'lookup_crate_docs',
75
+ { crateName: z.string().describe('Name of the Rust crate to lookup documentation for') },
76
+ ({ crateName }) => ({
77
+ messages: [
78
+ {
79
+ role: "user",
80
+ content: {
81
+ type: "text",
82
+ text: `Please analyze and summarize the documentation for the Rust crate '${crateName}'. Focus on:
83
+ 1. The main purpose and features of the crate
84
+ 2. Key types and functions
85
+ 3. Common usage patterns
86
+ 4. Any important notes or warnings
87
+ 5. VERY IMPORTANT: Latest Version
88
+
89
+ Documentation content will follow.`
90
+ }
91
+ }
92
+ ]
93
+ })
94
+ );
95
+
96
+ // Connect to the stdio transport and start the server
97
+ server.connect(new StdioServerTransport())
98
+ .then(() => {
99
+ console.error('MCP Crate Docs Server is running...');
100
+ })
101
+ .catch((err) => {
102
+ console.error('Failed to start MCP server:', err);
103
+ process.exit(1);
104
+ });
package/language.json ADDED
@@ -0,0 +1 @@
1
+ nodejs
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name": "iflow-mcp-rust-docs", "version": "1.0.0", "description": "MCP server for fetching Rust crate documentation", "main": "index.js", "bin": {"iflow-mcp-rust-docs": "index.js"}, "scripts": {"start": "node index.js", "build-ts": "tsc"}, "keywords": [], "author": "", "license": "MIT", "dependencies": {"@modelcontextprotocol/sdk": "^1.6.1", "axios": "^1.6.0", "html-to-text": "^9.0.5"}}
package/package_name ADDED
@@ -0,0 +1 @@
1
+ @iflow-mcp/0xkoda-rust-docs
package/push_info.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "push_platform": "github",
3
+ "fork_url": "https://github.com/iflow-mcp/0xkoda-mcp-rust-docs",
4
+ "fork_branch": "iflow"
5
+ }
@@ -0,0 +1 @@
1
+ {"serverConfig": "{\"mcpServers\":{\"rust-docs\":{\"command\":\"npx\",\"args\":[\"-y\",\"@iflow-mcp/0xkoda-rust-docs\"],\"values\":{}}}}"}