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

# Context

> Context API Documentation

export const RandomGradientBackground = ({className, color, children, grayscaled = false}) => {
  const saturation = useMemo(() => {
    if (color) {
      const values = color.split("(")[1].split(")")[0].trim().split(/\s+/);
      return parseFloat(values[1] || "0");
    }
    return grayscaled ? 0 : 0.2;
  }, [color, grayscaled]);
  const lightness = useMemo(() => {
    if (color) {
      const values = color.split("(")[1].split(")")[0].trim().split(/\s+/);
      return parseFloat(values[0] || "0.5");
    }
    return grayscaled ? 0.3 : 0.4;
  }, [color, grayscaled]);
  const randomHue = useMemo(() => {
    if (color) {
      const values = color.split("(")[1].split(")")[0].trim().split(/\s+/);
      return parseFloat(values[2] || "0");
    }
    return Math.floor(Math.random() * 360);
  }, [color]);
  const randomColor = useMemo(() => {
    if (color) {
      return color;
    }
    return `oklch(${Math.min(lightness, 1)} ${saturation} ${randomHue})`;
  }, [randomHue, saturation, lightness]);
  const lightColor = useMemo(() => {
    return `oklch(${Math.min(lightness * 2, 1)} ${saturation} ${randomHue})`;
  }, [randomHue, saturation, lightness, color]);
  const direction = useMemo(() => {
    return Math.floor(Math.random() * 360);
  }, [randomHue]);
  const brightnessFilter = useMemo(() => {
    return "1000%";
  }, []);
  return <div className={`relative overflow-hidden ${className || ""}`} style={{
    background: `${lightColor}`,
    minHeight: '100%',
    width: '100%'
  }}>
      <div className="absolute inset-0 w-full h-full" style={{
    background: `linear-gradient(${direction}deg, ${randomColor}, transparent), url(https://grainy-gradients.vercel.app/noise.svg)`,
    filter: `contrast(120%) brightness(${brightnessFilter})`,
    backgroundSize: 'cover',
    backgroundRepeat: 'no-repeat'
  }} />
      {children && <div className="relative z-10 w-full h-full">{children}</div>}
    </div>;
};

<Callout type="info" title="Source Code">
  View the source code for this module on GitHub: <a href="https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/context.py" target="_blank" rel="noopener noreferrer">[https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp\_use/server/context.py](https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/context.py)</a>
</Callout>

## Context

<div>
  <RandomGradientBackground className="rounded-lg p-4 w-full h-full rounded-full">
    <div className="text-black">
      <div className="text-black font-bold text-xl mb-2 mt-8"><code className="!text-black">class</code> Context</div>
    </div>
  </RandomGradientBackground>

  ```python theme={null}
  from mcp_use.server.context import Context
  ```

  <Card type="info">
    ### `method` **init**

    **Parameters**

    > <ParamField body="request_context" type="RequestContext[ServerSessionT, LifespanContextT, RequestT] | None" default="None">   Parameter value </ParamField>
    > <ParamField body="fastmcp" type="FastMCP | None" default="None">   Parameter value </ParamField>
    > <ParamField body="kwargs" type="Any" required="True">   Parameter value </ParamField>

    **Signature**

    ```python wrap theme={null}
    def __init__(request_context: RequestContext[ServerSessionT, LifespanContextT, RequestT] | None = None, fastmcp: FastMCP | None = None, kwargs: Any):
    ```
  </Card>

  <Card type="info">
    ### `method` get\_http\_request

    Return the underlying Starlette Request when running over HTTP transports.

    **Returns**

    >     <ResponseField name="returns" type="Request | None" />

    **Signature**

    ```python wrap theme={null}
    def get_http_request():
    ```
  </Card>

  <Card type="info">
    ### `method` list\_roots

    Request the list of roots from the client.

    Roots represent directories or files that the client has access to
    and wants to make available to the server.

    Example:

    ```python theme={null}
    @mcp.tool()
    async def analyze_workspace(ctx: Context) -> str:
        roots = await ctx.list_roots()
        if not roots:
            return "No roots provided by client"
        return f"Client has \{len(roots)\} root(s): \{[str(r.uri) for r in roots]\}"
    ```

    **Returns**

    > <ResponseField name="returns" type="list[Root]">A list of Root objects, each with a 'uri' (file:// URI) and optional 'name' field.</ResponseField>

    **Signature**

    ```python wrap theme={null}
    def list_roots():
    ```
  </Card>

  <Card type="info">
    ### `method` sample

    Request a client-side LLM sampling invocation.

    **Parameters**

    > <ParamField body="messages" type="str | SamplingMessage | Sequence[SamplingMessage | str]" required="True">   The sampling prompt(s). Accepts a simple string, a single </ParamField>
    > <ParamField body="max_tokens" type="int" default="512">   Maximum number of tokens to request from the client LLM. </ParamField>
    > <ParamField body="system_prompt" type="str | None" default="None">   Optional system instructions to prepend. </ParamField>
    > <ParamField body="include_context" type="bool | None" default="None">   Whether to ask the client to include MCP context. </ParamField>
    > <ParamField body="temperature" type="float | None" default="None">   Optional sampling temperature. </ParamField>
    > <ParamField body="stop_sequences" type="Sequence[str] | None" default="None">   Optional stop sequences to pass to the client LLM. </ParamField>
    > <ParamField body="metadata" type="dict[str, Any] | None" default="None">   Optional provider-specific metadata. </ParamField>
    > <ParamField body="model_preferences" type="ModelPreferences | None" default="None">   Optional hint about the desired model. </ParamField>
    > <ParamField body="raw" type="bool" default="False">   When `True` returns the full `CreateMessageResult` instead of </ParamField>

    **Returns**

    >     <ResponseField name="returns" type="CreateMessageResult" />

    **Signature**

    ```python wrap theme={null}
    def sample(
    messages: str | SamplingMessage | Sequence[SamplingMessage | str],
        max_tokens: int = 512,
        system_prompt: str | None = None,
        include_context: bool | None = None,
        temperature: float | None = None,
        stop_sequences: Sequence[str] | None = None,
        metadata: dict[str,
        Any] | None = None,
        model_preferences: ModelPreferences | None = None,
        raw: bool = False
    ):
    ```
  </Card>

  <Card type="info">
    ### `method` send\_prompt\_list\_changed

    Notify the client that the prompt list changed.

    **Signature**

    ```python wrap theme={null}
    def send_prompt_list_changed():
    ```
  </Card>

  <Card type="info">
    ### `method` send\_resource\_list\_changed

    Notify the client that the resource list changed.

    **Signature**

    ```python wrap theme={null}
    def send_resource_list_changed():
    ```
  </Card>

  <Card type="info">
    ### `method` send\_tool\_list\_changed

    Notify the client that the tool list changed.

    **Signature**

    ```python wrap theme={null}
    def send_tool_list_changed():
    ```
  </Card>
</div>
