# Using the MCP SDK

## Overview

The Gram MCP SDK wrapper provides low-level access to MCP features. This allows you to deploy an MCP server built using the [official MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk) to Gram functions.

![Choosing MCP SDK](/assets/docs/gram/img/functions/npm_mcp-framework.png)

## Basic usage

To deploy an existing MCP server or a new MCP server to Gram Functions using the MCP TypeScript SDK, you first need a file that exports an instance of `McpServer`.

```typescript

server.registerTool(
  "add",
  {
    title: "Addition Tool",
    description: "Add two numbers",
    inputSchema: { a: z.number(), b: z.number() },
  },
  async ({ a, b }) => {
    const output = { result: a + b };
    return {
      content: [{ type: "text", text: JSON.stringify(output) }],
    };
  },
);
```

A simple `gram.ts` file then wraps that server so it can be deployed to Gram Functions.

```typescript filename="gram.ts"

```

## Resources

MCP resources can also be deployed via Gram Functions when using the MCP SDK wrapper.

```typescript

server.registerResource(
  "a-cool-photo",
  "resources://a-cool-photo",
  {
    mimeType: "image/jpg",
    description: "This photo is really something",
    title: "A Cool Photo",
  },
  async (uri) => {
    let res = await fetch("https://picsum.photos/200/300.jpg");
    return {
      contents: [
        {
          uri: uri.href,
          blob: Buffer.from(await res.arrayBuffer()).toString("base64"),
        },
      ],
    };
  },
);
```

After running `push`, select the pushed resource to add it to a toolset.
![Adding a Resource](/assets/docs/gram/img/functions/adding-resources.png)

## Environment variables

Specify credentials or environment variable values that you need to make available in your tool runner environment. These can be provided either via stored Gram environments or via MCP headers set by the end user.

```typescript filename="gram.ts"

```

## Next steps

- [Build and deploy](/docs/mcp/build/gram-functions/build-deploy) Gram Functions.
