Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys, logging, platform, socket, getpass
- from datetime import datetime
- from typing import Any
- import httpx
- import subprocess
- from mcp.server.fastmcp import FastMCP
- __author__ = """Mark Pesce [email protected]"""
- __date__ = '$Date: 2025/05/24 20:37:00 $'.split()[1].replace('/', '-')
- __version__ = '$Revision: 0.1 $'.split()[1]
- # reconfigure UnicodeEncodeError prone default (i.e. windows-1252) to utf-8
- if sys.platform == "win32" and os.environ.get('PYTHONIOENCODING') is None:
- sys.stdin.reconfigure(encoding="utf-8")
- sys.stdout.reconfigure(encoding="utf-8")
- sys.stderr.reconfigure(encoding="utf-8")
- # Set up the logging
- logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%Y-%m-%d %I:%M:%S %p', level=logging.DEBUG)
- # Initialize FastMCP server
- mcp = FastMCP("mcp-tools")
- @mcp.tool()
- async def shell(command: str) -> str:
- """Pass a shell command for execution
- Args:
- command: A well-formatted bash command line
- Returns:
- Output from the shell of the command execution
- TODO:
- Make it stream output back to the LLM
- """
- try:
- result = subprocess.run(
- command,
- shell=True,
- capture_output=True,
- text=True,
- check=True
- )
- return result.stdout
- except subprocess.CalledProcessError as e:
- # Optionally return stderr or raise the exception
- return f"{e.stderr}"
- if __name__ == "__main__":
- # Initialize and run the server
- mcp.run(transport='stdio')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement