# HadeethEnc MCP Server

## Endpoint

```http
POST https://hadeethenc.com/mcp/
```

## Discovery

The MCP Server Card is published at:

```http
GET https://hadeethenc.com/.well-known/mcp/server-card.json
```

The draft alias is also available:

```http
GET https://hadeethenc.com/.well-known/mcp-server-card
```

For local development under XAMPP, use the matching local project URL, for example:

```http
POST http://localhost/hadith/mcp/
```

## Transport

This endpoint implements a simple stateless MCP Streamable HTTP server for PHP 7.3. It accepts JSON-RPC messages over HTTP `POST` and returns JSON responses directly.

The endpoint does not keep long-running SSE streams open. HTTP `GET` requests return `405 Method Not Allowed`.

## Available Tools

### `get_supported_languages`

Lists supported HadeethEnc language ISO codes and native language names.

Call this tool before searching or requesting details when the language code is unknown. It wraps:

```http
GET /api/v1/languages
```

### `search_hadeeths`

Searches HadeethEnc hadith texts by language and phrase.

#### Input Schema

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `language` | string | Yes | Language ISO code, for example `ar` or `en`. |
| `phrase` | string | Yes | Search phrase. It must contain from 3 to 120 UTF-8 characters. |

#### Result

The tool returns a text content item containing the JSON response from:

```http
GET /api/v1/hadeeths/search/?language={language_code}&phrase={search_phrase}
```

### `get_hadeeth_by_id`

Gets full details for one hadith by ID and language ISO code. It wraps:

```http
GET /api/v1/hadeeths/one/?language={language_code}&id={hadeeth_id}
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `language` | string | Yes | Language ISO code, for example `ar` or `en`. |
| `id` | string | Yes | Hadith ID. |

### `get_hadeeths_by_ids`

Gets full details for multiple hadiths by comma-separated IDs and language ISO code. It wraps:

```http
GET /api/v1/hadeeths/multiple/?language={language_code}&ids={hadeeth_id},{hadeeth_id}
```

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `language` | string | Yes | Language ISO code, for example `ar` or `en`. |
| `ids` | string | Yes | Comma-separated hadith IDs, for example `2962,4560`. |

## Example Messages

### Initialize

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-06-18",
    "capabilities": {},
    "clientInfo": {
      "name": "example-client",
      "version": "1.0.0"
    }
  }
}
```

### List Tools

```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list",
  "params": {}
}
```

### Call Search Tool

```json
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "search_hadeeths",
    "arguments": {
      "language": "ar",
      "phrase": "النية"
    }
  }
}
```

### Call Single Hadith Tool

```json
{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": {
    "name": "get_hadeeth_by_id",
    "arguments": {
      "language": "en",
      "id": "2962"
    }
  }
}
```

### Call Multiple Hadiths Tool

```json
{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "tools/call",
  "params": {
    "name": "get_hadeeths_by_ids",
    "arguments": {
      "language": "en",
      "ids": "2962,4560"
    }
  }
}
```

## Security Notes

- If an `Origin` header is provided, the endpoint accepts only requests from the same host by default.
- Additional browser origins may be allowed by setting the `HADITH_MCP_ALLOWED_ORIGINS` environment variable to a comma-separated list of exact origins.
- Production deployments should place this endpoint behind the same HTTPS and access-control policies used for the public API.
