> For the complete documentation index, see [llms.txt](https://docs.madjik.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.madjik.io/integration-guides/mcp-integration.md).

# Using Madjik API for MCP

Integrate Madjik data into AI models using the Model Context Protocol for enhanced context and decision-making.

## Overview

MCP (Model Context Protocol) provides a standardized way to give AI models access to external data and tools. Madjik API can serve as an MCP resource for crypto market context.

## MCP Server Implementation

### 1. Basic MCP Server for Madjik

```python
from mcp import Server, Resource

class MadjikMCPServer(Server):
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = "https://api.madjik.io/v1"
    
    @Resource("madjik://metrics/{metric_id}")
    def get_metric(self, metric_id: str):
        resp = requests.get(
            f"{self.base_url}/metrics/{metric_id}",
            headers={"Authorization": f"Bearer {self.api_key}"}
        )
        return resp.json()
    
    @Resource("madjik://market-summary")
    def get_market_summary(self):
        key_metrics = ["ME10030", "ME10014", "ME10016", "ME10010"]
        summary = {}
        for m in key_metrics:
            summary[m] = self.get_metric(m)
        return summary

# Start server
server = MadjikMCPServer(api_key="YOUR_API_KEY")
server.run()
```

### 2. MCP Resource Definitions

```json
{
  "resources": [
    {
      "uri": "madjik://metrics/me10030",
      "name": "Social Sentiment Index",
      "description": "Current crypto market sentiment (0-100)",
      "mimeType": "application/json"
    },
    {
      "uri": "madjik://metrics/me10016",
      "name": "Liquidation Risk Index", 
      "description": "Current liquidation cascade probability (0-100)",
      "mimeType": "application/json"
    },
    {
      "uri": "madjik://market-summary",
      "name": "Market Summary",
      "description": "Overview of key crypto market metrics",
      "mimeType": "application/json"
    }
  ]
}
```

### 3. Using Madjik MCP with Claude

```python
# Claude Desktop config (claude_desktop_config.json)
{
  "mcpServers": {
    "madjik": {
      "command": "python",
      "args": ["madjik_mcp_server.py"],
      "env": {
        "MADJIK_API_KEY": "your_api_key"
      }
    }
  }
}
```

Then in conversation:

> "What's the current crypto market sentiment according to Madjik?"

Claude will query `madjik://metrics/me10030` and respond with the data.

## MCP Tools for Madjik

```python
@Tool("analyze_market")
def analyze_market(timeframe: str = "1h"):
    """Analyze current crypto market conditions using Madjik metrics."""
    metrics = {
        "sentiment": get_metric("ME10030"),
        "risk": get_metric("ME10016"),
        "whale_activity": get_metric("ME10010"),
        "funding": get_metric("ME10014")
    }
    
    analysis = {
        "overall": "bullish" if metrics["sentiment"]["value"] > 60 else "bearish",
        "risk_level": "high" if metrics["risk"]["value"] > 70 else "normal",
        "smart_money": "accumulating" if metrics["whale_activity"]["value"] > 60 else "distributing"
    }
    
    return analysis
```

## Best Practices

1. **Cache MCP responses** - Reduce API calls, update periodically
2. **Provide descriptions** - Help AI understand metric meaning
3. **Include context** - Add related hypotheses to responses
4. **Handle errors** - Return graceful fallbacks

## See Also

* [AI Integration Guide](/integration-guides/ai-integration.md)
* [A2A Integration Guide](/integration-guides/a2a-integration.md)
* [All Metrics](https://github.com/madjik-io/madjik-api-docs/blob/main/metrics/README.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.madjik.io/integration-guides/mcp-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
