Python SDK for Gopher Security MCP - AI Agent orchestration framework with native performance
Project description
gopher-security-mcp Python SDK
Python SDK for gopher-security-mcp, providing AI agent orchestration with native C++ performance through ctypes FFI bindings.
Features
- Python 3.8+ compatibility
- pip/setuptools build system
- ctypes FFI bindings to native library
- GopherAgent class with builder pattern configuration
- Context manager support for automatic resource cleanup
- Typed errors (AgentError, ApiKeyError, ConnectionError, TimeoutError)
- Comprehensive test suite with pytest
Requirements
- Python 3.8 or higher
- Native gopher-security-mcp library (built from source)
Installation
From Source
- Clone the repository:
git clone https://github.com/GopherSecurity/gopher-mcp-python.git
cd gopher-mcp-python
- Build the native library:
./build.sh
- Install the Python package:
pip install -e .
Quick Start
Using API Key
from gopher_security_mcp import GopherAgent, GopherAgentConfig
# Create configuration with API key
config = (GopherAgentConfig.builder()
.provider("AnthropicProvider")
.model("claude-3-haiku-20240307")
.api_key("your-api-key")
.build())
# Create and use agent with context manager
with GopherAgent.create(config) as agent:
response = agent.run("What time is it in Tokyo?")
print(response)
Using JSON Server Configuration
from gopher_security_mcp import GopherAgent, GopherAgentConfig
# Create configuration with server config
config = (GopherAgentConfig.builder()
.provider("AnthropicProvider")
.model("claude-3-haiku-20240307")
.server_config('{"mcpServers": [...]}')
.build())
# Create agent
agent = GopherAgent.create(config)
try:
response = agent.run("What is the weather?")
print(response)
finally:
agent.dispose()
Using Convenience Methods
from gopher_security_mcp import GopherAgent
# Create with API key (shorthand)
agent = GopherAgent.create_with_api_key(
provider="AnthropicProvider",
model="claude-3-haiku-20240307",
api_key="your-api-key"
)
# Or with server config
agent = GopherAgent.create_with_server_config(
provider="AnthropicProvider",
model="claude-3-haiku-20240307",
server_config='{"mcpServers": [...]}'
)
Getting Detailed Results
from gopher_security_mcp import GopherAgent
with GopherAgent.create(config) as agent:
result = agent.run_detailed("What time is it?")
if result.is_success():
print(f"Response: {result.response}")
print(f"Iterations: {result.iteration_count}")
print(f"Tokens used: {result.tokens_used}")
elif result.is_timeout():
print(f"Request timed out: {result.error_message}")
else:
print(f"Error: {result.error_message}")
API Reference
GopherAgent
Main class for interacting with the gopher-security-mcp native library.
Static Methods
GopherAgent.init()- Initialize the library (called automatically)GopherAgent.shutdown()- Shutdown the libraryGopherAgent.is_initialized()- Check if library is initializedGopherAgent.create(config)- Create an agent with configurationGopherAgent.create_with_api_key(provider, model, api_key)- Convenience methodGopherAgent.create_with_server_config(provider, model, server_config)- Convenience method
Instance Methods
agent.run(query, timeout_ms=60000)- Run a query and get response stringagent.run_detailed(query, timeout_ms=60000)- Run a query and get AgentResultagent.dispose()- Release resourcesagent.is_disposed()- Check if agent is disposed
GopherAgentConfig
Configuration class with builder pattern.
config = (GopherAgentConfig.builder()
.provider("AnthropicProvider") # Required
.model("claude-3-haiku-20240307") # Required
.api_key("key") # Either api_key or server_config required
.server_config("{...}") # Either api_key or server_config required
.build())
AgentResult
Result class with status and metadata.
result.response- Response textresult.status- AgentResultStatus enumresult.iteration_count- Number of iterationsresult.tokens_used- Tokens consumedresult.error_message- Error message (if applicable)result.is_success()- Check if successfulresult.is_error()- Check if errorresult.is_timeout()- Check if timeout
Exceptions
AgentError- Base exception for agent errorsApiKeyError- Invalid API keyConnectionError- Connection failedTimeoutError- Operation timed out
Development
Running Tests
pytest
Code Formatting
This project uses Black for code formatting and Ruff for linting.
Format code:
black .
Check formatting without modifying:
black --check .
Run linter:
ruff check .
Fix linting issues:
ruff check --fix .
Building the Native Library
./build.sh
Clean Build
./build.sh --clean
Environment Variables
GOPHER_SECURITY_MCP_LIBRARY_PATH- Custom path to native libraryDEBUG- Enable debug output for library loading
License
See LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gopher_security_mcp-0.1.0.dev20260227124047.tar.gz.
File metadata
- Download URL: gopher_security_mcp-0.1.0.dev20260227124047.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0e42f5ba60fa672ec26ac2c2a7f29a95dc48aa5ff996f8135f8d1b94784d1bb
|
|
| MD5 |
877f4d111330ba5fb45592ae3bf2d83e
|
|
| BLAKE2b-256 |
d1f093d8021ba76cf2aacad3e947fcd1877074da34cdf847add768cb66d7d609
|
File details
Details for the file gopher_security_mcp-0.1.0.dev20260227124047-py3-none-any.whl.
File metadata
- Download URL: gopher_security_mcp-0.1.0.dev20260227124047-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91cf5b2d0ff5f6d652f257e82206b95326f6ebf007dc67ddb323da253e10cd14
|
|
| MD5 |
a9c77b9686b0da023662b0592ebb742f
|
|
| BLAKE2b-256 |
ab9710d24a364d518d5db2dbaad1c132668e14de2b55f2fbc031daa081917c11
|