🚀 Hello World

This commit is contained in:
Felix Rieseberg 2025-06-26 08:38:59 -07:00
commit 0172c07623
No known key found for this signature in database
4 changed files with 11896 additions and 0 deletions

View file

@ -0,0 +1,77 @@
{
"dxt_version": "0.1",
"name": "file-manager-python",
"display_name": "Python File Manager MCP",
"version": "0.1.0",
"description": "A Python MCP server for file operations",
"long_description": "This extension provides file management capabilities through a Python MCP server. It demonstrates Python-based Desktop Extension development, including file operations, directory management, and proper MCP protocol implementation.",
"author": {
"name": "Anthropic",
"email": "support@anthropic.com",
"url": "https://github.com/anthropics"
},
"server": {
"type": "python",
"entry_point": "server/main.py",
"mcp_config": {
"command": "python",
"args": [
"${__dirname}/server/main.py",
"--workspace=${user_config.workspace_directory}"
],
"env": {
"DEBUG": "${user_config.debug_mode}",
"PYTHONPATH": "${__dirname}/server/lib"
}
}
},
"tools": [
{
"name": "list_files",
"description": "List files in a directory"
},
{
"name": "read_file",
"description": "Read file contents"
},
{
"name": "get_file_info",
"description": "Get information about a file"
}
],
"keywords": [
"file",
"directory",
"python",
"management",
"filesystem"
],
"license": "MIT",
"user_config": {
"workspace_directory": {
"type": "directory",
"title": "Workspace Directory",
"description": "Directory to use as workspace",
"default": "${HOME}/Documents",
"required": false
},
"debug_mode": {
"type": "boolean",
"title": "Debug Mode",
"description": "Enable debug output",
"default": false,
"required": false
}
},
"compatibility": {
"claude_desktop": ">=0.10.0",
"platforms": [
"darwin",
"win32",
"linux"
],
"runtimes": {
"python": ">=3.8.0 <4"
}
}
}

View file

@ -0,0 +1,31 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "file-manager-python"
version = "0.1.0"
description = "A Python MCP server for file operations"
authors = [
{name = "Anthropic", email = "support@anthropic.com"}
]
license = {text = "MIT"}
classifiers = [
"Private :: Do Not Upload" # Prevents accidental uploads to PyPI
]
[project.dependencies]
mcp = ">=1.0.0"
trio = ">=0.22.0"
[tool.setuptools]
packages = ["server"]
[project.scripts]
bundle-deps = "python:install_deps"
# Custom scripts section for DXT development
[tool.dxt]
bundle = "pip install \"mcp[all]\" --target server/lib --upgrade --force-reinstall"
test = "python server/main.py --debug"
pack = "npx @anthropic-ai/dxt pack"

View file

@ -0,0 +1,2 @@
mcp>=1.0.0
trio>=0.22.0

View file

@ -0,0 +1,112 @@
#!/usr/bin/env python3
import os
import sys
import argparse
from pathlib import Path
from mcp.server.fastmcp import FastMCP
# Parse command line arguments
parser = argparse.ArgumentParser(description="File Manager MCP Server")
parser.add_argument(
"--workspace", default=os.path.expanduser("~/Documents"), help="Workspace directory"
)
parser.add_argument("--debug", action="store_true", help="Enable debug mode")
args = parser.parse_args()
# Initialize server
mcp = FastMCP("file-manager-python")
@mcp.tool()
def list_files(path: str) -> str:
"""List files in a directory"""
path_obj = Path(path)
if not path_obj.exists():
return f"Directory not found: {path}"
if not path_obj.is_dir():
return f"Path is not a directory: {path}"
try:
files = []
for item in path_obj.iterdir():
file_type = "directory" if item.is_dir() else "file"
files.append(f"{item.name} ({file_type})")
if not files:
return f"Directory is empty: {path}"
file_list = "\n".join(files)
return f"Files in {path}:\n{file_list}"
except PermissionError:
return f"Permission denied accessing: {path}"
except Exception as e:
return f"Error listing directory: {str(e)}"
@mcp.tool()
def read_file(path: str) -> str:
"""Read file contents"""
path_obj = Path(path)
if not path_obj.exists():
return f"File not found: {path}"
if not path_obj.is_file():
return f"Path is not a file: {path}"
try:
with path_obj.open("r", encoding="utf-8") as f:
content = f.read()
return f"Contents of {path}:\n{content}"
except UnicodeDecodeError:
return f"File is not text or uses unsupported encoding: {path}"
except PermissionError:
return f"Permission denied reading: {path}"
except Exception as e:
return f"Error reading file: {str(e)}"
@mcp.tool()
def get_file_info(path: str) -> str:
"""Get information about a file"""
path_obj = Path(path)
if not path_obj.exists():
return f"Path not found: {path}"
try:
stat_info = path_obj.stat()
file_type = "directory" if path_obj.is_dir() else "file"
info = [
f"Path: {path}",
f"Type: {file_type}",
f"Size: {stat_info.st_size} bytes",
f"Modified: {stat_info.st_mtime}",
f"Created: {stat_info.st_ctime}",
]
info_text = "\n".join(info)
return f"File Info:\n{info_text}"
except PermissionError:
return f"Permission denied accessing: {path}"
except Exception as e:
return f"Error getting file info: {str(e)}"
# Main execution
if __name__ == "__main__":
# Debug output if enabled
if args.debug:
print("Starting File Manager MCP Server...", file=sys.stderr)
print(f"Workspace: {args.workspace}", file=sys.stderr)
# Run the server
mcp.run()