A comprehensive LLM server that integrates Ollama for local language model inference with Model Context Protocol (MCP) support for tool usage, including advanced geospatial analysis.
- Ollama Integration: Connect to local Ollama models
- MCP Support: Built-in Model Context Protocol for tool integration
- OpenAI-Compatible API: Standard chat completions endpoint
- Streaming Support: Real-time response streaming
- Geospatial Analysis Tools: List, analyze, and visualize geospatial layers
- Built-in Tools: File operations, web search, calculator, and more
- FastAPI Backend: High-performance async API server
- Install Ollama: Download and install from ollama.ai
- Pull Models: Download models you want to use
ollama pull llama2 ollama pull mistral ollama pull codellama
-
Install dependencies:
pip install -r requirements.txt
-
Start the server:
python llm_server.py
The server will start on http://localhost:8000
POST /chat/completionsOpenAI-compatible endpoint for chat completions, with tool support.
Example Request:
{
"model": "llama2",
"messages": [
{"role": "user", "content": "What layers are available?"}
],
"tools": true,
"stream": false
}GET /modelsReturns available Ollama models.
GET /toolsReturns available MCP tools (including geospatial tools).
POST /mcp/execute_tool?tool_name=<tool_name>Execute an MCP tool directly.
GET /healthServer health status.
- read_file: Read file contents
- web_search: Search the web using DuckDuckGo
- get_page_content: Fetch and extract text content from any web page
- validate_url: Check if a URL is accessible and get basic information
- calculate: Perform mathematical calculations
- list_layers: List all available geospatial layers
- find_layer_by_name: Find a layer by its name
- get_layer_info: Get detailed information about a specific layer
- analyze_population: Analyze population data in a layer
- filter_features: Filter features in a layer by attribute conditions
- get_attribute_stats: Get statistics for a specific attribute in a layer
- spatial_analysis: Perform spatial operations (buffer, intersection, etc.)
- create_map_visualization: Create a map visualization with styled features
- analyze_layer_attributes: Comprehensive attribute analysis for a layer
The web search tool now provides real browser-based search capabilities:
- DuckDuckGo Integration: Uses both API and HTML scraping for comprehensive results
- Instant Answers: Gets direct answers for factual queries
- Definitions: Provides definitions for terms and concepts
- Related Topics: Suggests related information and links
- Fallback Search: HTML scraping when API doesn't return results
- Clean Results: Properly formatted with titles, snippets, and URLs
# Basic web search
{
"model": "llama2",
"messages": [
{"role": "user", "content": "Search for information about quantum computing"}
],
"tools": ["web_search"]
}
# Get page content from a specific URL
{
"model": "llama2",
"messages": [
{"role": "user", "content": "Get the content from https://example.com/article"}
],
"tools": ["get_page_content"]
}
# Validate a URL before accessing
{
"model": "llama2",
"messages": [
{"role": "user", "content": "Check if https://example.com is accessible"}
],
"tools": ["validate_url"]
}import requests
response = requests.post("http://localhost:8000/chat/completions", json={
"model": "llama2",
"messages": [
{"role": "user", "content": "What is the capital of France?"}
]
})
print(response.json())response = requests.post("http://localhost:8000/chat/completions", json={
"model": "llama2",
"messages": [
{"role": "user", "content": "Analyze the attributes of the tl 2024 36 place layer"}
],
"tools": true
})
print(response.json())response = requests.post(
"http://localhost:8000/mcp/execute_tool?tool_name=list_layers",
json={}
)
print(response.json())You can add custom MCP tools by extending the MCPServer class in llm_server.py. See the code for examples.
The server runs on:
- Host: 0.0.0.0 (all interfaces)
- Port: 8000
- Reload: Enabled in development mode
Modify the uvicorn.run() call in `