Skip to content

Commit

Permalink
Minor updates to filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
maheshmurag committed Nov 20, 2024
1 parent 124ff86 commit 64f8e4d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 60 deletions.
42 changes: 20 additions & 22 deletions src/duckduckgo/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
# DuckDuckGo MCP Server

MCP server providing search functionality via DuckDuckGo's HTML interface.

## Core Concepts
## Components

### Resources
Single resource endpoint for search results:
Single resource endpoint for search interface:
```duckduckgo://search```

### Tools
Search tool with configurable result count:
```json
- **duckduckgo_search**
- Performs a search using DuckDuckGo and returns the top search results
- Inputs:
- `query` (string, required): The search query to look up
- `numResults` (number, optional): Number of results to return (default: 10)
- Returns titles, snippets, and URLs of the search results

## Usage Example
```javascript
// Example tool call
{
"name": "search",
"name": "duckduckgo_search",
"arguments": {
"query": "your search query",
"numResults": 5 // optional, defaults to 5
"numResults": 10
}
}
```

## 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
```typescript
// Search tool response format
// Example response format:
{
content: [{
type: "text",
text: "Title: Example Result\nSnippet: Result description...\nURL: https://..."
"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.
3 changes: 2 additions & 1 deletion src/duckduckgo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const SEARCH_TOOL: Tool = {
name: "duckduckgo_search",
description:
"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: {
type: "object",
properties: {
Expand Down
12 changes: 7 additions & 5 deletions src/duckduckgo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
"bin": {
"mcp-server-duckduckgo": "dist/index.js"
},
"files": ["dist"],
"files": [
"dist"
],
"scripts": {
"build": "tsc && shx chmod +x dist/*.js",
"prepare": "npm run build",
"watch": "tsc --watch"
},
"dependencies": {
"@modelcontextprotocol/sdk": "0.5.0",
"jsdom": "^24.0.0",
"jsdom": "^24.1.3",
"node-fetch": "^3.3.2"
},
"devDependencies": {
"shx": "^0.3.4",
"typescript": "^5.6.2",
"@types/jsdom": "^21.1.6",
"@types/node": "^20.10.0"
"@types/node": "^20.10.0",
"shx": "^0.3.4",
"typescript": "^5.6.2"
}
}
90 changes: 59 additions & 31 deletions src/filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
- Search files
- 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

### Resources
Expand All @@ -32,24 +18,66 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio

### Tools

1. `read_file`: Read file contents
2. `read_multiple_files`: Read multiple files
3. `write_file`: Create/overwrite file
4. `create_directory`: Create directory
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

- Uses `@modelcontextprotocol/sdk`
- Async file operations with `fs/promises`
- Type guards for argument validation
- Error handling and detailed descriptions
- **read_file**
- Read complete contents of a file
- Input: `path` (string)
- Reads complete file contents with UTF-8 encoding

- **read_multiple_files**
- Read multiple files simultaneously
- Input: `paths` (string[])
- Failed reads won't stop the entire operation

- **write_file**
- Create new file or overwrite existing
- Inputs:
- `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

- 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
1 change: 0 additions & 1 deletion src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
name: "write_file",
description:
"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. " +
"Handles text content with proper encoding.",
inputSchema: {
Expand Down

0 comments on commit 64f8e4d

Please sign in to comment.