|
| 1 | +import asyncio |
| 2 | +import os |
| 3 | + |
| 4 | +import httpx |
| 5 | +from mcp.server.fastmcp import FastMCP |
| 6 | + |
| 7 | +# Initialize MCP server |
| 8 | +mcp = FastMCP( |
| 9 | + name="Agentic Security MCP Server", |
| 10 | + description="MCP server to interact with LLM scanning test", |
| 11 | + dependencies=["httpx"], |
| 12 | +) |
| 13 | + |
| 14 | +# FastAPI Server Configuration |
| 15 | +AGENTIC_SECURITY = "http://0.0.0.0:8718" |
| 16 | + |
| 17 | + |
| 18 | +@mcp.tool() |
| 19 | +async def verify_llm(spec: str) -> dict: |
| 20 | + """Verify an LLM model specification using the FastAPI server.""" |
| 21 | + url = f"{AGENTIC_SECURITY}/verify" |
| 22 | + async with httpx.AsyncClient() as client: |
| 23 | + response = await client.post(url, json={"spec": spec}) |
| 24 | + return response.json() |
| 25 | + |
| 26 | + |
| 27 | +@mcp.tool() |
| 28 | +async def start_scan( |
| 29 | + llmSpec: str, |
| 30 | + maxBudget: int, |
| 31 | + optimize: bool = False, |
| 32 | + enableMultiStepAttack: bool = False, |
| 33 | +) -> dict: |
| 34 | + """Start an LLM security scan via the FastAPI server.""" |
| 35 | + url = f"{AGENTIC_SECURITY}/scan" |
| 36 | + payload = { |
| 37 | + "llmSpec": llmSpec, |
| 38 | + "maxBudget": maxBudget, |
| 39 | + "datasets": [], |
| 40 | + "optimize": optimize, |
| 41 | + "enableMultiStepAttack": enableMultiStepAttack, |
| 42 | + "probe_datasets": [], |
| 43 | + "secrets": {}, |
| 44 | + } |
| 45 | + async with httpx.AsyncClient() as client: |
| 46 | + response = await client.post(url, json=payload) |
| 47 | + return response.json() |
| 48 | + |
| 49 | + |
| 50 | +@mcp.tool() |
| 51 | +async def stop_scan() -> dict: |
| 52 | + """Stop an ongoing scan via the FastAPI server.""" |
| 53 | + url = f"{AGENTIC_SECURITY}/stop" |
| 54 | + async with httpx.AsyncClient() as client: |
| 55 | + response = await client.post(url) |
| 56 | + return response.json() |
| 57 | + |
| 58 | + |
| 59 | +@mcp.tool() |
| 60 | +async def get_data_config() -> list: |
| 61 | + """Retrieve data configuration from the FastAPI server.""" |
| 62 | + url = f"{AGENTIC_SECURITY}/v1/data-config" |
| 63 | + async with httpx.AsyncClient() as client: |
| 64 | + response = await client.get(url) |
| 65 | + return response.json() |
| 66 | + |
| 67 | + |
| 68 | +@mcp.tool() |
| 69 | +async def get_spec_templates() -> list: |
| 70 | + """Retrieve data configuration from the FastAPI server.""" |
| 71 | + url = f"{AGENTIC_SECURITY}/v1/llm-specs" |
| 72 | + async with httpx.AsyncClient() as client: |
| 73 | + response = await client.get(url) |
| 74 | + return response.json() |
| 75 | + |
| 76 | + |
| 77 | +# Run the MCP server |
| 78 | +if __name__ == "__main__": |
| 79 | + mcp.run() |
0 commit comments