Py概述
一个CLI工具和模型上下文协议(MCP)服务器,使您能够直接检查Python模块和类,提供全面的文档、方法、类和结构信息。
概述
PyOverview是一个功能强大的工具,它提供了Python模块和类的全面概述。它既可以用作独立的CLI工具,也可以用作MCP服务器,以弥合LLM和Python代码库之间的差距。它允许动态检查和理解Python模块、类、函数及其关系,而不需要静态分析或预先生成的文档。
但是为什么呢?
编码LLM通常基于过时的半熟文档做出决定,这些文档可能正在进行中(就像人类一样)。这个MCP切入了真相的源头,并经常展示文档中根本没有提到的方法,让你在正确的级别上与库进行交互。
> inspect the fastmcp.client module and note the functions useful for testing
⏺ I'll inspect the fastmcp.client module to identify functions useful for testing. Let me use
the pyoverview MCP server to examine this module.
⏺ pyoverview - inspect_module (MCP)(target: "fastmcp.client")
⎿ 🔬 Inspecting: fastmcp.client
├── 🏛️ Classes
│ ├── BearerAuth - Base class for all authentication schemes.
… +128 lines (ctrl+r to expand)
⏺ Now let me get more detailed information about the Client class and its methods, as this
appears to be the main class for testing:
⏺ pyoverview - inspect_module (MCP)(target: "fastmcp.client.Client", short: false)
⎿ 🔬 Inspecting: fastmcp.client.Client
├── 📦 Properties/Attributes
│ ├── initialize_result: property
… +300 lines (ctrl+r to expand)
⏺ Now let me also look at the transport classes, particularly FastMCPTransport which is
mentioned as useful for testing:
⏺ pyoverview - inspect_module (MCP)(target: "fastmcp.client.FastMCPTransport")
⎿ 🔬 Inspecting: fastmcp.client.FastMCPTransport
├── 📦 Properties/Attributes
│ └── _abc_impl: _abc_data
… +21 lines (ctrl+r to expand)
⏺ Let me also check what testing utilities might be available in the auth module:
⏺ pyoverview - inspect_module (MCP)(target: "fastmcp.client.auth")
⎿ 🔬 Inspecting: fastmcp.client.auth
├── 🏛️ Classes
│ ├── BearerAuth - Base class for all authentication schemes.
… +21 lines (ctrl+r to expand)
⏺ Based on my inspection of the fastmcp.client module, here are the key functions and classes
useful for testing:
Core Testing Classes
Client - Main MCP client class with extensive testing capabilities:
- Context manager support (async with client:)
- Connection state checking (is_connected())
- Session management with reference counting for reentrant contexts
FastMCPTransport - In-memory transport ideal for unit tests:
- Connects directly to FastMCP server instances in the same Python process
- No network overhead, perfect for testing scenarios
- Works with both FastMCP 2.x and 1.0 servers
Key Testing Methods
Tool Testing
- call_tool(name, arguments) - High-level tool calling with automatic error raising
- call_tool_mcp(name, arguments) - Raw MCP protocol tool calling, returns complete result
object
- list_tools() - Get available tools for validation
Resource Testing
- read_resource(uri) - Read resource contents
- list_resources() - List available resources
- list_resource_templates() - List resource templates
Prompt Testing
- get_prompt(name, arguments) - Retrieve rendered prompts
- list_prompts() - List available prompts
Connection Testing
- is_connected() - Check connection state
- ping() - Test server connectivity
- new() - Create fresh client instances for independent test sessions
Protocol Testing
All methods have _mcp variants (e.g., call_tool_mcp()) that return raw MCP protocol results,
useful for testing protocol compliance and error handling.
Authentication Testing
- BearerAuth - For testing bearer token authentication
- OAuth - For testing OAuth flows (though less useful for unit tests)
Testing Utilities
The reentrant context manager design is particularly valuable for testing concurrent
scenarios, allowing multiple async with client: blocks to share the same session safely.
The FastMCPTransport is the most important class for testing as it enables in-process testing
without network dependencies.特性
- 动态模块检查:在运行时导入和分析任何Python模块
- 丰富的可视化:具有颜色编码类别的美丽树形结构输出
- 综合分析:提取方法、类、属性和文档
- 结构化数据:返回人类可读和机器可解析的结果
- MCP集成:与Claude和其他兼容MCP的AI助手无缝集成
安全
MCP中的S代表安全。我建议您始终在某种沙箱中运行MCP,并将API和SSH密钥排除在它们的环境之外。就这个特定的MCP而言,您应该知道它正在对模块进行动态检查,即它们是由MCP执行的解释器加载的。如果模块编写奇怪,这可能会导致意外的代码执行和副作用。相应地管理自己。
安装
先决条件
- Python 3.13或更高版本
- uv包管理器(推荐)
使用uvx安装(推荐)
直接从GitHub运行,无需克隆:
uvx --from git+https://github.com/closed-systems/pyoverview pyoverview使用uv进行安装
git clone https://github.com/closed-systems/pyoverview
cd pyoverview
uv sync使用pip安装
git clone https://github.com/closed-systems/pyoverview
cd pyoverview
pip install -e .用法
作为MCP服务器
运行服务器,使其对MCP兼容客户端可用:
python pyoverview.py --mcp支持的目标格式
这 inspect_module 该工具接受各种目标格式:
- 模块:
src.sample_lib - 类:
src.sample_lib.MyClass - 嵌套属性:
module.submodule.ClassName
工具参考
inspect_module(target: str)
检查Python模块或类,并返回有关其结构的详细信息。
参数:
target:模块或类的完整导入路径(例如,“src.sample_lib”或“src.samples_lib.MyClass”)
退货:
- 具有树形结构的富格式文本输出
- 结构化数据包含:
- modules:带文档的子模块 - classes:带有文档字符串的类 - functions:带有签名和文档的函数/方法 - attributes:具有类型信息的属性和变量
输出示例
检查模块时(pyoverview),您将看到(打开短输出):
🔬 Inspecting: pyoverview
├── 📦 Properties/Attributes
│ ├── Dict: _SpecialGenericAlias
│ ├── List: _SpecialGenericAlias
│ └── server: FastMCP
├── 🔧 Methods/Functions
│ ├── inspect_module(target: str, short=False) -> fastmcp.tools.tool.ToolResult - A Python MCP (Module Control Panel) to inspect modules and classes.
│ ├── inspect_target(target_obj: Any) -> Dict[str, List[Dict]] - Inspects an object, builds a rich Tree, and returns a dictionary of its members.
│ └── render_tree(structure: Dict[str, List[Dict]], target: str, short) -
├── 🏛️ Classes
│ ├── Any - Special type indicating an unconstrained type.
│ ├── Console - A high level console interface.
│ ├── FastMCP - Abstract base class for generic types.
│ ├── Path - PurePath subclass that can make system calls.
│ ├── TextContent - Text content for a message.
│ ├── ToolResult -
│ └── Tree - A renderable for a tree structure.
└── 📦 Modules
├── importlib - A pure Python implementation of import.
├── inspect - Get useful information from live Python objects.
└── sys - This module provides access to some objects used or maintained by the询问此模块的LLM将看到上述内容,以及所请求模块/类的结构化JSON表示。由于可能导致的疯狂,我们不会迭代地检查模块。
在进行最终检查时,我发现富显示库实际上有自己的Python对象函数的奇特表示。它提供了更多的信息并使用了更多的颜色,我不确定额外的数据是否会帮助LLM或混淆它们的上下文。
项目结构
pyoverview/
- README.md # This file
- pyproject.toml # Project configuration
- pyoverview.py # Main CLI and MCP server implementation
- uv.lock # Dependency lock file依赖项
- fastmcp:用于构建MCP服务器的FastMCP框架
- 富有的:丰富的文本和优美的格式
Claude桌面配置
要将此MCP服务器与Claude Desktop一起使用,请将以下内容添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"pyoverview": {
"command": "uvx",
"args": ["--from", "git+https://github.com/closed-systems/pyoverview", "pyoverview", "--mcp"],
}
}
}贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 提交拉取请求
许可证
这个项目是开源的。请检查存储库以了解许可证详细信息。
例子
检查标准库模块
import asyncio
from pyoverview import inspect_module
async def inspect_datetime():
# Inspect the datetime module
result = await inspect_module("datetime")
print(result.content[0].text)
# Inspect a specific class
result = await inspect_module("datetime.datetime")
print(result.content[0].text)
asyncio.run(inspect_datetime())故障排除
常见问题
- 模块声音错误:确保目标模块在Python路径中
- 属性错误:验证指定模块中是否存在类或属性
- 导入错误:检查是否已安装目标模块的所有依赖项
调试模式
有关详细的错误信息,请使用Python的verbose标志运行服务器:
python -v pyoverview.py --mcp与开发工作流集成
PyOverview特别适用于:
- 代码文档:从实时代码自动生成文档
- API发现:探索不熟悉的代码库和库
- 重构:了解类层次结构和依赖关系
- 测试:验证模块结构和可用方法
