Spaces:
Sleeping
Sleeping
File size: 7,597 Bytes
4786618 |
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 |
# Обновление конфигурации MCP для SobroJuriBert
После развертывания SobroJuriBert, обнови конфигурацию MCP:
## 1. Обнови файл конфигурации
Отредактируй `/mnt/c/Users/s7/AppData/Roaming/Claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"C:\\Users\\s7\\Documents",
"C:\\sobro-mcp"
]
},
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
},
"sobrojuribert": {
"command": "C:\\Users\\s7\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe",
"args": [
"C:\\sobro-mcp\\sobrojuribert_mcp.py"
]
}
}
}
```
## 2. Создай новый MCP сервер
Создай файл `C:\sobro-mcp\sobrojuribert_mcp.py`:
```python
#!/usr/bin/env python3
"""SobroJuriBert MCP Server"""
import asyncio
from typing import Any
import aiohttp
from mcp.server.models import InitializationOptions
from mcp.server import NotificationOptions, Server
import mcp.server.stdio
import mcp.types as types
API_URL = "https://sobroinc-sobrojuribert.hf.space"
async def run_server():
server = Server("sobrojuribert-mcp")
session = None
@server.list_tools()
async def handle_list_tools() -> list[types.Tool]:
return [
types.Tool(
name="juribert_mask_fill",
description="Fill [MASK] tokens in French legal text",
inputSchema={
"type": "object",
"properties": {
"text": {"type": "string", "description": "Text with [MASK] tokens"},
"top_k": {"type": "integer", "default": 5}
},
"required": ["text"]
}
),
types.Tool(
name="juribert_embeddings",
description="Generate embeddings for French legal texts",
inputSchema={
"type": "object",
"properties": {
"texts": {"type": "array", "items": {"type": "string"}}
},
"required": ["texts"]
}
),
types.Tool(
name="juribert_ner",
description="Extract entities from French legal text",
inputSchema={
"type": "object",
"properties": {
"text": {"type": "string"}
},
"required": ["text"]
}
),
types.Tool(
name="juribert_classify",
description="Classify French legal documents",
inputSchema={
"type": "object",
"properties": {
"text": {"type": "string"}
},
"required": ["text"]
}
),
types.Tool(
name="juribert_analyze_contract",
description="Analyze French legal contracts",
inputSchema={
"type": "object",
"properties": {
"text": {"type": "string"},
"contract_type": {"type": "string"}
},
"required": ["text"]
}
)
]
@server.call_tool()
async def handle_call_tool(name: str, arguments: dict) -> list[types.TextContent]:
nonlocal session
if session is None:
session = aiohttp.ClientSession()
try:
endpoint_map = {
"juribert_mask_fill": "/mask-fill",
"juribert_embeddings": "/embeddings",
"juribert_ner": "/ner",
"juribert_classify": "/classify",
"juribert_analyze_contract": "/analyze-contract"
}
endpoint = endpoint_map.get(name)
if not endpoint:
return [types.TextContent(type="text", text=f"Unknown tool: {name}")]
async with session.post(
f"{API_URL}{endpoint}",
json=arguments,
timeout=aiohttp.ClientTimeout(total=30)
) as response:
result = await response.json()
# Format response based on tool
if name == "juribert_mask_fill":
text = f"Predictions for: {result['input']}\n"
for pred in result['predictions']:
text += f"- {pred['sequence']} (score: {pred['score']:.3f})\n"
elif name == "juribert_embeddings":
text = f"Generated {len(result['embeddings'])} embeddings "
text += f"(dimension: {result['dimension']})"
elif name == "juribert_ner":
text = f"Found {len(result['entities'])} entities:\n"
for ent in result['entities']:
text += f"- {ent['text']} ({ent['type']})\n"
elif name == "juribert_classify":
text = f"Document classification:\n"
text += f"Primary: {result['primary_category']}\n"
text += f"Confidence: {result['confidence']:.1%}\n"
elif name == "juribert_analyze_contract":
text = f"Contract Analysis:\n"
text += f"Type: {result['contract_type']}\n"
text += f"Parties: {len(result['parties'])}\n"
text += f"Key clauses: {', '.join(result['key_clauses'])}\n"
if result['missing_clauses']:
text += f"Missing: {', '.join(result['missing_clauses'])}\n"
return [types.TextContent(type="text", text=text)]
except Exception as e:
return [types.TextContent(type="text", text=f"Error: {str(e)}")]
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
InitializationOptions(
server_name="sobrojuribert-mcp",
server_version="1.0.0",
capabilities=server.get_capabilities(
notification_options=NotificationOptions(),
experimental_capabilities={},
),
),
)
if session:
await session.close()
def main():
asyncio.run(run_server())
if __name__ == "__main__":
main()
```
## 3. Перезапусти Claude Desktop
После обновления конфигурации, перезапусти Claude Desktop.
## 4. Используй новые команды
```
Используй juribert_mask_fill с текстом "Le contrat est signé entre les [MASK]"
Используй juribert_ner для извлечения сущностей из "Le Tribunal de Grande Instance de Paris"
Классифицируй документ с помощью juribert_classify
Проанализируй контракт с помощью juribert_analyze_contract
``` |