> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dedaluslabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompts

> List and render prompts from MCP servers

# Prompts

> List and render prompts from MCP servers

Prompts are reusable message templates exposed by the server. A prompt can accept **string-valued arguments** and returns a sequence of messages you can feed into an LLM conversation.

**If you’re new to this:** think of a prompt as a **pre-written chat script** stored on the server (like “summarize” or “code review”). Your client can **list** the available scripts, then **render** one into actual messages (optionally filling in arguments like `"language": "python"`).

## List prompts

Discover available prompts:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from dedalus_mcp.client import open_connection

async with open_connection("http://127.0.0.1:8000/mcp") as client:
    prompts = await client.list_prompts()

    for p in prompts.prompts:
        print(f"{p.name}: {p.description}")
```

## Prompt schema

Each prompt includes:

| Field         | Type           | Description                 |
| ------------- | -------------- | --------------------------- |
| `name`        | `str`          | Prompt identifier           |
| `description` | `str \| None`  | What the prompt does        |
| `arguments`   | `list \| None` | Required/optional arguments |

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
for p in prompts.prompts:
    print(f"Name: {p.name}")
    print(f"Description: {p.description}")
    if p.arguments:
        for arg in p.arguments:
            required = "(required)" if arg.required else "(optional)"
            print(f"  - {arg.name}: {arg.description} {required}")
```

## Get a prompt

Render a prompt with arguments:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
result = await client.get_prompt("summarize", {"style": "brief"})
print(result.messages)
```

**Note**: MCP prompt arguments are strings. If a server expects structured input (lists/dicts), it will usually ask you to pass a JSON string and parse it server-side.

## Response structure

A rendered prompt returns a `GetPromptResult`:

| Field         | Type          | Description               |
| ------------- | ------------- | ------------------------- |
| `messages`    | `list`        | Rendered message sequence |
| `description` | `str \| None` | Optional description      |

Each message has a `role` and a `content` block. Many prompts return text content; some may return non-text content blocks.

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from dedalus_mcp import types

result = await client.get_prompt("code-review", {"language": "python"})

for msg in result.messages:
    content = msg.content
    if isinstance(content, types.TextContent):
        text = content.text
    else:
        text = f"<{content.type} content>"
    print(f"[{msg.role}] {text}")
```

## Example: Code assistant

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import asyncio
from dedalus_mcp.client import MCPClient
from dedalus_mcp import types

async def main():
    client = await MCPClient.connect("http://127.0.0.1:8000/mcp")
    try:
        prompts = await client.list_prompts()
        print("Available prompts:")
        for p in prompts.prompts:
            print(f"  - {p.name}: {p.description}")

        result = await client.get_prompt(
            "explain-code",
            {
                "language": "python",
                "code": "def fib(n): return n if n < 2 else fib(n-1) + fib(n-2)",
            },
        )

        print("\nRendered prompt:")
        for msg in result.messages:
            if isinstance(msg.content, types.TextContent):
                print(f"[{msg.role}] {msg.content.text}")
            else:
                print(f"[{msg.role}] <{msg.content.type} content>")

    finally:
        await client.close()

asyncio.run(main())
```

## Prompts without arguments

Some prompts don’t require arguments:

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
result = await client.get_prompt("greeting")
# or explicitly:
result = await client.get_prompt("greeting", {})
```

## Context manager

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from dedalus_mcp.client import open_connection

async with open_connection("http://127.0.0.1:8000/mcp") as client:
    prompts = await client.list_prompts()
    result = await client.get_prompt("analyze", {"data": "sample"})
```
