Minor updates to filesystem

This commit is contained in:
Mahesh Murag
2024-11-20 01:24:23 -05:00
parent 124ff86101
commit 64f8e4db05
5 changed files with 90 additions and 62 deletions

View File

@@ -1,39 +1,37 @@
# DuckDuckGo MCP Server # DuckDuckGo MCP Server
MCP server providing search functionality via DuckDuckGo's HTML interface. MCP server providing search functionality via DuckDuckGo's HTML interface.
## Core Concepts ## Components
### Resources ### Resources
Single resource endpoint for search results: Single resource endpoint for search interface:
```duckduckgo://search``` ```duckduckgo://search```
### Tools ### Tools
Search tool with configurable result count: - **duckduckgo_search**
```json - Performs a search using DuckDuckGo and returns the top search results
{ - Inputs:
"name": "search", - `query` (string, required): The search query to look up
"arguments": { - `numResults` (number, optional): Number of results to return (default: 10)
"query": "your search query", - Returns titles, snippets, and URLs of the search results
"numResults": 5 // optional, defaults to 5
}
}
```
## Implementation Details
- HTML scraping via JSDOM
- Clean result formatting with titles, snippets, and URLs
- Error handling for network/parsing issues
- Request rate limiting built-in via DuckDuckGo's interface
## Usage Example ## Usage Example
```typescript ```javascript
// Search tool response format // Example tool call
{ {
content: [{ "name": "duckduckgo_search",
type: "text", "arguments": {
text: "Title: Example Result\nSnippet: Result description...\nURL: https://..." "query": "your search query",
"numResults": 10
}
}
// Example response format:
{
"content": [{
"type": "text",
"text": "Title: Result Title\nSnippet: Result description...\nURL: https://example.com\n\nTitle: Another Result\n..."
}] }]
} }
``` ```
## Development
Requires Node.js and npm. Uses ES modules.

View File

@@ -16,7 +16,8 @@ const SEARCH_TOOL: Tool = {
name: "duckduckgo_search", name: "duckduckgo_search",
description: description:
"Performs a search using DuckDuckGo and returns the top search results. " + "Performs a search using DuckDuckGo and returns the top search results. " +
"Returns titles, snippets, and URLs of the search results. ", "Returns titles, snippets, and URLs of the search results. " +
"Use this tool to search for current information on the internet.",
inputSchema: { inputSchema: {
type: "object", type: "object",
properties: { properties: {

View File

@@ -10,7 +10,9 @@
"bin": { "bin": {
"mcp-server-duckduckgo": "dist/index.js" "mcp-server-duckduckgo": "dist/index.js"
}, },
"files": ["dist"], "files": [
"dist"
],
"scripts": { "scripts": {
"build": "tsc && shx chmod +x dist/*.js", "build": "tsc && shx chmod +x dist/*.js",
"prepare": "npm run build", "prepare": "npm run build",
@@ -18,13 +20,13 @@
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "0.5.0", "@modelcontextprotocol/sdk": "0.5.0",
"jsdom": "^24.0.0", "jsdom": "^24.1.3",
"node-fetch": "^3.3.2" "node-fetch": "^3.3.2"
}, },
"devDependencies": { "devDependencies": {
"shx": "^0.3.4",
"typescript": "^5.6.2",
"@types/jsdom": "^21.1.6", "@types/jsdom": "^21.1.6",
"@types/node": "^20.10.0" "@types/node": "^20.10.0",
"shx": "^0.3.4",
"typescript": "^5.6.2"
} }
} }

View File

@@ -10,20 +10,6 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
- Search files - Search files
- Get file metadata - Get file metadata
## Usage
1. Install dependencies:
```
npm install @modelcontextprotocol/sdk
```
2. Run server:
```
node index.js
```
3. Server runs on stdio, communicate using MCP.
## API ## API
### Resources ### Resources
@@ -32,24 +18,66 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
### Tools ### Tools
1. `read_file`: Read file contents - **read_file**
2. `read_multiple_files`: Read multiple files - Read complete contents of a file
3. `write_file`: Create/overwrite file - Input: `path` (string)
4. `create_directory`: Create directory - Reads complete file contents with UTF-8 encoding
5. `list_directory`: List directory contents
6. `delete_file`: Delete file/directory
7. `move_file`: Move/rename file/directory
8. `search_files`: Search files/directories
9. `get_file_info`: Get file metadata
## Implementation - **read_multiple_files**
- Read multiple files simultaneously
- Input: `paths` (string[])
- Failed reads won't stop the entire operation
- Uses `@modelcontextprotocol/sdk` - **write_file**
- Async file operations with `fs/promises` - Create new file or overwrite existing
- Type guards for argument validation - Inputs:
- Error handling and detailed descriptions - `path` (string): File location
- `content` (string): File content
- **create_directory**
- Create new directory or ensure it exists
- Input: `path` (string)
- Creates parent directories if needed
- Succeeds silently if directory exists
- **list_directory**
- List directory contents with [FILE] or [DIR] prefixes
- Input: `path` (string)
- **delete_file**
- Remove files or directories
- Inputs:
- `path` (string)
- `recursive` (boolean, optional): For directory deletion
- Use with caution - deletions are permanent
- **move_file**
- Move or rename files and directories
- Inputs:
- `source` (string)
- `destination` (string)
- Fails if destination exists
- **search_files**
- Recursively search for files/directories
- Inputs:
- `path` (string): Starting directory
- `pattern` (string): Search pattern
- Case-insensitive matching
- Returns full paths to matches
- **get_file_info**
- Get detailed file/directory metadata
- Input: `path` (string)
- Returns:
- Size
- Creation time
- Modified time
- Access time
- Type (file/directory)
- Permissions
## Notes ## Notes
- Careful with `delete_file` and `write_file` (overwrites existing) - Exercise caution with `delete_file` (deletes files permanently) and `write_file` (overwrites existing files)
- File paths can be absolute or relative - File paths can be absolute or relative

View File

@@ -153,7 +153,6 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
name: "write_file", name: "write_file",
description: description:
"Create a new file or completely overwrite an existing file with new content. " + "Create a new file or completely overwrite an existing file with new content. " +
"This tool will create any necessary parent directories automatically. " +
"Use with caution as it will overwrite existing files without warning. " + "Use with caution as it will overwrite existing files without warning. " +
"Handles text content with proper encoding.", "Handles text content with proper encoding.",
inputSchema: { inputSchema: {