Jump to content

Recommended Posts

Posted

Today, I was following the MCP course and set up a local MCP server for testing.

However, I encountered an issue where the MCP server doesn't function properly when Kaspersky is enabled. 
It works fine when I temporarily pause Kaspersky.

I suspect that the SSE Connection might be blocked, but I couldn't find any settings to adjust this. 
Of course, my assumption could be incorrect.

Has anyone else experienced or resolved this issue?

I tested on Windows 11.

To replicate the issue, you can follow these steps:

1) Run the Python code below. 
You can find this code at the provided link. 
https://learn.deeplearning.ai/courses/mcp-build-rich-context-ai-apps-with-anthropic/lesson/dbabg/creating-an-mcp-server

Save the file as mcp_chatbot.py.

2) Execute the following command:
npx @modelcontextprotocol/inspector uv run mcp_chatbot.py


3) Once you see the message "MCP Inspector is up and running at http://127.0.0.1:6274" 
open http://127.0.0.1:6274


4) Click the Connect button.
You should encounter the error: "Connection Error, is your MCP server running?"

5) Error details
 

Quote

Error in /message route: Error: SSE connection not established
    at SSEServerTransport.handlePostMessage (file:///C:/Users/testuser/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:61:19)
    at file:///C:/Users/testuser/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:262:25
    at Layer.handleRequest (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\lib\layer.js:152:17)
    at next (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\lib\route.js:157:13)
    at Route.dispatch (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\lib\route.js:117:3)
    at handle (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\index.js:435:11)
    at Layer.handleRequest (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\lib\layer.js:152:17)
    at C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\index.js:295:15
    at processParams (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\index.js:582:12)
    at next (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\router\index.js:291:5)
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (node:_http_outgoing:659:11)
    at ServerResponse.header (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\express\lib\response.js:684:10)
    at ServerResponse.json (C:\Users\testuser\AppData\Local\npm-cache\_npx\5a9d879542beca3a\node_modules\express\lib\response.js:247:10)
    at file:///C:/Users/testuser/AppData/Local/npm-cache/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:266:25
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)




Screen shot :  Works and Error version

image.thumb.png.50e2c72521ea52ad384a4f13c7650a49.pngmcp_server_error.thumb.png.3fd5b28adc3e8f74dcd6e66f9f3efcce.png

Python Code

Quote

import arxiv import json import os from typing import List from mcp.server.fastmcp import FastMCP PAPER_DIR = "papers" # Initialize FastMCP server mcp = FastMCP("research") @mcp.tool() def search_papers(topic: str, max_results: int = 5) -> List[str]: """ Search for papers on arXiv based on a topic and store their information. Args: topic: The topic to search for max_results: Maximum number of results to retrieve (default: 5) Returns: List of paper IDs found in the search """ # Use arxiv to find the papers client = arxiv.Client() # Search for the most relevant articles matching the queried topic search = arxiv.Search( query=topic, max_results=max_results, sort_by=arxiv.SortCriterion.Relevance ) papers = client.results(search) # Create directory for this topic path = os.path.join(PAPER_DIR, topic.lower().replace(" ", "_")) os.makedirs(path, exist_ok=True) file_path = os.path.join(path, "papers_info.json") # Try to load existing papers info try: with open(file_path, "r") as json_file: papers_info = json.load(json_file) except (FileNotFoundError, json.JSONDecodeError): papers_info = {} # Process each paper and add to papers_info paper_ids = [] for paper in papers: paper_ids.append(paper.get_short_id()) paper_info = { 'title': paper.title, 'authors': [author.name for author in paper.authors], 'summary': paper.summary, 'pdf_url': paper.pdf_url, 'published': str(paper.published.date()) } papers_info[paper.get_short_id()] = paper_info # Save updated papers_info to json file with open(file_path, "w") as json_file: json.dump(papers_info, json_file, indent=2) print(f"Results are saved in: {file_path}") return paper_ids @mcp.tool() def extract_info(paper_id: str) -> str: """ Search for information about a specific paper across all topic directories. Args: paper_id: The ID of the paper to look for Returns: JSON string with paper information if found, error message if not found """ for item in os.listdir(PAPER_DIR): item_path = os.path.join(PAPER_DIR, item) if os.path.isdir(item_path): file_path = os.path.join(item_path, "papers_info.json") if os.path.isfile(file_path): try: with open(file_path, "r") as json_file: papers_info = json.load(json_file) if paper_id in papers_info: return json.dumps(papers_info[paper_id], indent=2) except (FileNotFoundError, json.JSONDecodeError) as e: print(f"Error reading {file_path}: {str(e)}") continue return f"There's no saved information related to paper {paper_id}." if __name__ == "__main__": mcp.run(transport='stdio')

 

harlan4096
Posted

Welcome to Kaspersky Comminty.

 

Please provide version of K. product installed.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...