# How to create Pinecone MCP server in JS?

**URL:** <https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962>\
**Category:** General\
**Tags:** pinecone-assistant\
**Created:** [May 8, 2025, 11:21am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962 "2025-05-08T11:21:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauravmindzk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/gauravmindzk/32/3835_2.png) [@gauravmindzk](https://community.pinecone.io/u/gauravmindzk)\
**Post date:** [May 8, 2025, 11:21am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/1 "2025-05-08T11:21:41Z")

</div>

> **[Use an Assistant MCP server - Pinecone Docs](https://docs.pinecone.io/guides/assistant/mcp-server)**
>
> Search through billions of items for similar matches to any object, in milliseconds. It's the next generation of search, an API call away.

the documentation only has integration guide in python.  
is it possible to have a similar setup in javascript ( nodejs ) ?

---

<div class="post-metadata">

**Author:** ![avi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/avi/32/3505_2.png) [@avi](https://community.pinecone.io/u/avi)\
**Post date:** [May 8, 2025, 1:31pm UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/2 "2025-05-08T13:31:33Z")

</div>

In general, to use the remote MCP you only need to feed your assistant’s url into an MCP client; the Python code provided only demonstrated using the MCP via Langchain.  
Can you elaborate more on your use case?

---

<div class="post-metadata">

**Author:** ![gauravmindzk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/gauravmindzk/32/3835_2.png) [@gauravmindzk](https://community.pinecone.io/u/gauravmindzk)\
**Post date:** [May 9, 2025, 5:20am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/3 "2025-05-09T05:20:00Z")

</div>

hi @avi ,  
my app’s backend is written in nodejs and I want to develop a chatbot in my application powered by Pinecone Assistant’s MCP server.  
I’ve found the javascript code for uploading data to the Pinecone Assistant ( [Upload files - Pinecone Docs](https://docs.pinecone.io/guides/assistant/upload-files#upload-a-local-file) )

I want a similar code for ( [Use an Assistant MCP server - Pinecone Docs](https://docs.pinecone.io/guides/assistant/mcp-server#use-with-langchain) ) this .  
Below is my agent’s code using Python:

```auto
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
import asyncio
from langgraph.checkpoint.mongodb.aio import AsyncMongoDBSaver

mcp_endpoint = f"pinecone-mcp-endpoint"
MONGODB_URI = "mongo-db-uri"

async def main():
    model = ChatOpenAI(model="gpt-4o-mini", api_key='openai-api-key')
    
    # Create the MongoDB client and checkpointer inside the async context
    async with AsyncMongoDBSaver.from_conn_string(MONGODB_URI) as checkpointer:
        async with MultiServerMCPClient(
            {
                "pinecone_assistant": {
                    "url": mcp_endpoint,
                    "transport": "sse",
                    "headers": {
                        "Authorization": f"Bearer pinecone-api-key"
                    }
                }
            }
        ) as client:
            agent = create_react_agent(model, client.get_tools(), checkpointer=checkpointer)
            config = {"configurable": {"thread_id": "1"}}
            response = await agent.ainvoke({"messages": "hello"}, config)
            print(response["messages"][-1].content)

# Run the async function
if __name__ == " __main__":
    asyncio.run(main())

```

I want its equivalent in javascript .

---

<div class="post-metadata">

**Author:** ![gauravmindzk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/gauravmindzk/32/3835_2.png) [@gauravmindzk](https://community.pinecone.io/u/gauravmindzk)\
**Post date:** [May 9, 2025, 6:56am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/4 "2025-05-09T06:56:24Z")

</div>

I came across Langchain’s github repo [GitHub - langchain-ai/langchainjs-mcp-adapters: Adapters for integrating Model Context Protocol (MCP) tools with LangChain.js applications, supporting both stdio and SSE transports.](https://github.com/langchain-ai/langchainjs-mcp-adapters)  
and tried setting up the code .

```auto
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

// Create client and connect to server
const client = new MultiServerMCPClient({
  // Global tool configuration options
  // Whether to throw on errors if a tool fails to load (optional, default: true)
  throwOnLoadError: true,
  // Whether to prefix tool names with the server name (optional, default: true)
  prefixToolNameWithServerName: true,
  // Optional additional prefix for tool names (optional, default: "mcp")
  additionalToolNamePrefix: "mcp",
  // Server configuration
  mcpServers: {
    pinecone_assistant: {
      url: "pinecone-mcp-server-url",
      transport: "sse",
      headers: {
        Authorization:
          "Bearer pinecone-api-key",
      },
      useNodeEventSource: true,
      reconnect: {
        enabled: true,
        maxAttempts: 5,
        delayMs: 2000,
      },
    },
  },
});

const tools = await client.getTools();

// Create an OpenAI model
const model = new ChatOpenAI({
  modelName: "gpt-4o-mini",
  temperature: 0,
  apiKey:"openai-api-key"
});

// Create the React agent
const agent = createReactAgent({
  llm: model,
  tools,
});

// Run the agent
try {
  const aiResponse = await agent.invoke({
    messages: [{ role: "user", content: "hello" }],
  });
  console.log(aiResponse);
} catch (error) {
  console.error("Error during agent execution:", error);
  // Tools throw ToolException for tool-specific errors
  if (error.name === "ToolException") {
    console.error("Tool execution failed:", error.message);
  }
}

await client.close();

```

PS C:\Users\gaura\Desktop\Chatbot\> node agent.js  
(node:22864) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.  
(Use node --trace-deprecation … to show where the warning was created)  
file:///C:/Users/gaura/Desktop/Chatbot/node\_modules/@langchain/mcp-adapters/dist/client.js:434  
throw new MCPClientError(Failed to create SSE transport for server “${serverName}”: ${error}, serverName);  
^  
MCPClientError: Failed to create SSE transport for server “pinecone\_assistant”: MCPClientError: Failed to connect to SSE server “pinecone\_assistant”: Error: SSE error: Non-200 status code (401)  
at MultiServerMCPClient.\_initializeSSEConnection (file:///C:/Users/gaura/Desktop/Chatbot/node\_modules/@langchain/mcp-adapters/dist/client.js:434:19)  
at process.processTicksAndRejections (node:internal/process/task\_queues:105:5)  
at async MultiServerMCPClient.initializeConnections (file:///C:/Users/gaura/Desktop/Chatbot/node\_modules/@langchain/mcp-adapters/dist/client.js:297:17)  
at async MultiServerMCPClient.getTools (file:///C:/Users/gaura/Desktop/Chatbot/node\_modules/@langchain/mcp-adapters/dist/client.js:314:9)  
at async file:///C:/Users/gaura/Desktop/Chatbot/agent.js:33:15 {  
serverName: ‘pinecone\_assistant’  
}  
Node.js v22.11.0

my js code is throwing error, looks like its not able to connect with the MCP server , what may be wrong in my code ?

---

<div class="post-metadata">

**Author:** ![avi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/avi/32/3505_2.png) [@avi](https://community.pinecone.io/u/avi)\
**Post date:** [May 9, 2025, 3:56pm UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/5 "2025-05-09T15:56:46Z")

</div>

401 is unauthorized error. Double check your assistant’s MCP url and Api key.

---

<div class="post-metadata">

**Author:** ![avi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/avi/32/3505_2.png) [@avi](https://community.pinecone.io/u/avi)\
**Post date:** [May 9, 2025, 4:02pm UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/6 "2025-05-09T16:02:43Z")

</div>

But it seems that you are in the right direction; checking Langchain’s docs for the proper setting and putting your assistant’s url and API key in the correct plane.  
I would like to help you make it work, please let me know if you have any more problems.

---

<div class="post-metadata">

**Author:** ![gauravmindzk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/gauravmindzk/32/3835_2.png) [@gauravmindzk](https://community.pinecone.io/u/gauravmindzk)\
**Post date:** [May 12, 2025, 4:34am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/7 "2025-05-12T04:34:18Z")

</div>

yeah, I get it.  
MCP url and API key are 100% correct, and my code also looks correct. I don’t know why is it giving 401 error.

---

<div class="post-metadata">

**Author:** ![avi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/avi/32/3505_2.png) [@avi](https://community.pinecone.io/u/avi)\
**Post date:** [May 12, 2025, 6:15am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/8 "2025-05-12T06:15:07Z")

</div>

You are indeed 100% right, it is reproducible.  
There is a [bug](https://github.com/langchain-ai/langchainjs-mcp-adapters/issues/65) in Langchain’s JS implementation, and someone already [suggested a fix](https://github.com/langchain-ai/langchainjs-mcp-adapters/pull/58).

---

<div class="post-metadata">

**Author:** ![avi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/avi/32/3505_2.png) [@avi](https://community.pinecone.io/u/avi)\
**Post date:** [May 12, 2025, 12:50pm UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/9 "2025-05-12T12:50:05Z")

</div>

@gauravmindzk FYI I’m working on getting this fix in, will update

---

<div class="post-metadata">

**Author:** ![gauravmindzk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/gauravmindzk/32/3835_2.png) [@gauravmindzk](https://community.pinecone.io/u/gauravmindzk)\
**Post date:** [May 13, 2025, 4:33am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/10 "2025-05-13T04:33:06Z")

</div>

thanks @avi , really appreciate it 🤗

---

<div class="post-metadata">

**Author:** ![avi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/avi/32/3505_2.png) [@avi](https://community.pinecone.io/u/avi)\
**Post date:** [May 14, 2025, 4:40pm UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/11 "2025-05-14T16:40:04Z")

</div>

Sorry for the latency here, they publish new version soon after we asked them to fix but I didn’t get into testing it. Can you try again with the new version?

---

<div class="post-metadata">

**Author:** ![gauravmindzk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/gauravmindzk/32/3835_2.png) [@gauravmindzk](https://community.pinecone.io/u/gauravmindzk)\
**Post date:** [May 15, 2025, 5:06am UTC](https://community.pinecone.io/t/how-to-create-pinecone-mcp-server-in-js/7962/12 "2025-05-15T05:06:27Z")

</div>

hey @avi , will try again and let you know
