File size: 6,661 Bytes
5aaaef8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# MCP Client Configuration Examples

This document provides configuration examples for connecting various MCP clients to the hf-eda-mcp server.

## Table of Contents

- [Kiro IDE](#kiro-ide)
- [Claude Desktop](#claude-desktop)
- [Custom MCP Client](#custom-mcp-client)
- [Environment Variables](#environment-variables)

---

## Kiro IDE

### Workspace Configuration

Create or edit `.kiro/settings/mcp.json` in your workspace:

```json
{
  "mcpServers": {
    "hf-eda-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-p", "7860:7860",
        "--env-file", ".env",
        "hf-eda-mcp:latest"
      ],
      "env": {
        "HF_TOKEN": "${HF_TOKEN}"
      },
      "disabled": false,
      "autoApprove": [
        "get_dataset_metadata",
        "get_dataset_sample",
        "analyze_dataset_features"
      ]
    }
  }
}
```

### User-Level Configuration

Edit `~/.kiro/settings/mcp.json` for global configuration:

```json
{
  "mcpServers": {
    "hf-eda-mcp": {
      "command": "pdm",
      "args": ["run", "hf-eda-mcp"],
      "env": {
        "HF_TOKEN": "your_token_here"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}
```

### Using HuggingFace Spaces

```json
{
  "mcpServers": {
    "hf-eda-mcp": {
      "url": "https://your-username-hf-eda-mcp.hf.space/gradio_api/mcp/sse",
      "disabled": false,
      "autoApprove": ["get_dataset_metadata"]
    }
  }
}
```

---

## Claude Desktop

### Configuration File Location

- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
- **Linux**: `~/.config/Claude/claude_desktop_config.json`

### Local Server Configuration

```json
{
  "mcpServers": {
    "hf-eda-mcp": {
      "command": "python",
      "args": ["-m", "hf_eda_mcp"],
      "env": {
        "HF_TOKEN": "your_token_here",
        "PYTHONPATH": "/path/to/hf-eda-mcp/src"
      }
    }
  }
}
```

### Docker Configuration

```json
{
  "mcpServers": {
    "hf-eda-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-p", "7860:7860",
        "-e", "HF_TOKEN=your_token_here",
        "hf-eda-mcp:latest"
      ]
    }
  }
}
```

### HuggingFace Spaces Configuration

```json
{
  "mcpServers": {
    "hf-eda-mcp": {
      "url": "https://your-username-hf-eda-mcp.hf.space/gradio_api/mcp/sse"
    }
  }
}
```

---

## Custom MCP Client

### Python Client Example

```python
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def main():
    # Connect to local server
    server_params = StdioServerParameters(
        command="python",
        args=["-m", "hf_eda_mcp"],
        env={"HF_TOKEN": "your_token_here"}
    )
    
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            # Initialize the connection
            await session.initialize()
            
            # List available tools
            tools = await session.list_tools()
            print("Available tools:", tools)
            
            # Call a tool
            result = await session.call_tool(
                "get_dataset_metadata",
                arguments={"dataset_id": "squad"}
            )
            print("Result:", result)

if __name__ == "__main__":
    asyncio.run(main())
```

### JavaScript/TypeScript Client Example

```typescript
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

async function main() {
  const transport = new StdioClientTransport({
    command: "python",
    args: ["-m", "hf_eda_mcp"],
    env: {
      HF_TOKEN: process.env.HF_TOKEN
    }
  });

  const client = new Client({
    name: "hf-eda-client",
    version: "1.0.0"
  }, {
    capabilities: {}
  });

  await client.connect(transport);

  // List tools
  const tools = await client.listTools();
  console.log("Available tools:", tools);

  // Call a tool
  const result = await client.callTool({
    name: "get_dataset_metadata",
    arguments: {
      dataset_id: "squad"
    }
  });
  console.log("Result:", result);

  await client.close();
}

main().catch(console.error);
```

---

## Environment Variables

### Required Variables

- `HF_TOKEN`: HuggingFace API token (optional for public datasets, required for private datasets)

### Optional Variables

- `HF_HOME`: Directory for HuggingFace cache (default: `~/.cache/huggingface`)
- `HF_DATASETS_CACHE`: Directory for datasets cache
- `TRANSFORMERS_CACHE`: Directory for transformers cache
- `GRADIO_SERVER_NAME`: Server host (default: `0.0.0.0`)
- `GRADIO_SERVER_PORT`: Server port (default: `7860`)
- `MCP_SERVER_ENABLED`: Enable MCP server (default: `true`)

### Example .env File

```bash
# HuggingFace Authentication
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Cache Configuration
HF_HOME=/path/to/cache
HF_DATASETS_CACHE=/path/to/cache/datasets
TRANSFORMERS_CACHE=/path/to/cache/transformers

# Server Configuration
GRADIO_SERVER_NAME=0.0.0.0
GRADIO_SERVER_PORT=7860
MCP_SERVER_ENABLED=true
```

---

## Deployment Options Comparison

| Option | Pros | Cons | Best For |
|--------|------|------|----------|
| **Local (PDM)** | Fast, easy debugging | Requires Python setup | Development |
| **Docker** | Isolated, reproducible | Requires Docker | Production, CI/CD |
| **HF Spaces** | Hosted, no maintenance | Limited control | Public sharing |

---

## Troubleshooting

### Connection Issues

1. **Server not starting**: Check logs for errors, verify dependencies installed
2. **Authentication failed**: Verify `HF_TOKEN` is set correctly
3. **Port already in use**: Change `GRADIO_SERVER_PORT` to a different port

### Tool Execution Issues

1. **Dataset not found**: Verify dataset ID is correct on HuggingFace Hub
2. **Permission denied**: Ensure `HF_TOKEN` has access to private datasets
3. **Timeout errors**: Increase timeout settings or use smaller sample sizes

### Docker Issues

1. **Image build fails**: Ensure all dependencies in `pyproject.toml` are compatible
2. **Container exits immediately**: Check logs with `docker logs hf-eda-mcp-server`
3. **Cache not persisting**: Verify volume mounts in `docker-compose.yml`

---

## Additional Resources

- [MCP Protocol Documentation](https://modelcontextprotocol.io/)
- [Gradio MCP Integration](https://www.gradio.app/guides/gradio-and-mcp)
- [HuggingFace Hub Documentation](https://huggingface.co/docs/hub/index)
- [Project Repository](https://github.com/your-username/hf-eda-mcp)