-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
45 lines (34 loc) · 1.04 KB
/
file.py
File metadata and controls
45 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# import os
# from mcp.server.fastmcp import FastMCP
# mcp = FastMCP()
# @mcp.tool()
# def get_downloads_files():
# """获取下载文件夹下的文件列表"""
# return os.listdir(os.path.expanduser("~/Downloads"))
# if __name__ == "__main__":
# mcp.run(transport="stdio")
import os
import sys
import logging
from mcp.server.fastmcp import FastMCP
# 设置日志
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
filename='/tmp/mcp_debug.log'
)
logger = logging.getLogger(__name__)
try:
logger.debug("初始化 FastMCP")
mcp = FastMCP()
@mcp.tool()
def get_downloads_files():
"""获取下载文件夹下的文件列表"""
logger.debug("调用 get_downloads_files 函数")
return os.listdir(os.path.expanduser("~/Downloads"))
if __name__ == "__main__":
logger.debug("开始运行 MCP 服务")
mcp.run(transport="stdio")
except Exception as e:
logger.error(f"发生错误: {e}", exc_info=True)
sys.exit(1)