diff --git a/.cursor/write-challenge-lesson.mdc b/.cursor/write-challenge-lesson.mdc new file mode 100644 index 000000000..eaaecb4bb --- /dev/null +++ b/.cursor/write-challenge-lesson.mdc @@ -0,0 +1,131 @@ +--- +description: +globs: +alwaysApply: false +--- +# Write a Challenge lesson + +Write a practical challenge lesson that guides learners through implementing concepts they learned in previous theory lessons. The lesson should be hands-on, step-by-step, and focused on creating something functional. Use a encouraging but direct tone that assumes the learner has absorbed the theoretical concepts and is ready to apply them practically. + +## Constraints + +- Keep the lesson focused on one primary implementation goal +- Provide specific, actionable steps with exact commands and code +- Use simple, clear language with no motivational fluff +- Include practical testing and verification steps +- Ensure the challenge builds directly on previous lesson concepts +- Make the outcome immediately testable and verifiable +- Focus on getting something working rather than explaining theory +- Use consistent naming and examples throughout +- Form a checklist of instructions that users can follow step-by-step +- All content should be written in AsciiDoc format +- Use bullet point outlines from the lesson file to create hands-on challenges + +## Required Structure + +### 1. Challenge Introduction + +- Start with a short, succinct recap of the previous lesson (read the directory alphabetically to find the previous lesson content) +- Follow with a single paragraph stating what the reader will do to complete the challenge +- Use format: "In this challenge, you will [action] using [method/tool]" +- Clear statement of the practical goal + +### 2. Challenge Goals + +- Numbered list (1-5 goals maximum) of specific, measurable outcomes +- Each goal should be actionable and verifiable +- Goals should build logically toward the final implementation + +### 3. Step-by-Step Instructions + +Break implementation into logical steps (typically 4-6 steps) forming a checklist of instructions: + +#### Step Structure: +- **Step N: [Action-oriented title]** (use second-level headings like a to-do or checklist) +- Brief explanation of what this step accomplishes +- Exact commands to run (in code blocks) +- Code to write (in code blocks with filenames) +- Any important notes or explanations +- Instructions should be concise and describe what the user should do + +#### Essential Steps to Include: +- Project setup and initialization +- Dependency installation +- Core implementation (the main code) +- Configuration and integration +- Testing and verification + +### 4. Verification Section + +- Clear checklist of what should be working +- Specific tests or examples to try +- Expected outcomes or behaviors +- Simple troubleshooting hints if needed + +### 5. Next Steps Section + +- Congratulatory statement acknowledging completion +- Brief summary of what was accomplished +- Connection to the bigger picture or learning objectives + +### 6. Experimentation Tips + +- Optional "[TIP] Experiment further" section +- 3-4 specific suggestions for extending the implementation +- Focus on variations or enhancements, not completely new concepts + +### 7. Summary Section + +- Use AsciiDoc format: `[.summary]` and `== Summary` +- Provide a one-paragraph summary of the actions that the user has carried out +- Can use bullet points with **bold key concepts** learned for more complex challenges +- Brief description of each major accomplishment +- Reference to the next lesson topic + +Example formats: +```asciidoc +[.summary] +== Summary + +You can now install the `neo4j` library and connect to Neo4j by creating a new driver instance. + +In the next lesson, you will learn how to execute your first Cypher query. +``` + +Or for more complex challenges: +```asciidoc +[.summary] +== Summary + +In this challenge, you demonstrated how to use the `neo4j` library to connect to Neo4j. +``` + +## Implementation Guidelines + +### Using Bullet Point Outlines: +- If the lesson file contains bullet point outlines, use them to create hands-on challenges +- Convert each bullet point into a concrete, actionable step +- Maintain the logical flow and structure of the original outline +- Transform abstract concepts into specific implementation tasks + +### Code and Commands: +- Always provide exact, copy-pasteable code +- Use consistent file names and project structure +- Include command-line instructions with proper syntax +- Specify which directory to run commands from + +### Testing: +- Include real-world testing scenarios +- Use actual tools and environments (VS Code, browsers, etc.) +- Provide specific examples to test with +- Make verification steps concrete and measurable + +### Tone: +- Encouraging but matter-of-fact +- Assume competence while providing clear guidance +- Celebrate success without excessive enthusiasm +- Focus on practical outcomes over learning theory + +## Instruction + +Write the final lesson content directly using AsciiDoc format. Do not include bullet points, notes, or meta-commentary. This is the learner-facing copy that guides them through the complete implementation challenge. diff --git a/.cursor/write-lesson-summary.mdc b/.cursor/write-lesson-summary.mdc new file mode 100644 index 000000000..302eadf28 --- /dev/null +++ b/.cursor/write-lesson-summary.mdc @@ -0,0 +1,40 @@ +--- +description: +globs: +alwaysApply: false +--- +Add a succinct bullet point summary of the information convered in the lesson to the summary section at the bottom of the page. + +Write the content in asciidoc, do not use markdown. + +Here is an example of a good summary: + +```asciidoc +[.summary] +== Summary + +The Model Context Protocol (MCP) consists of several key elements: + +* **Servers** - Provide capabilities through tools, resources, and prompt templates in a client-server architecture +* **Clients** - Manage one-to-one connections to servers and request available tools, resources, and prompt templates +* **Hosts** - Applications (like Claude Desktop, Amazon Q, or Cursor) that maintain session state, manage clients, and decide which tools to use + +In the next lesson, you will learn how to install your first MCP server. + +``` + +You can also provide a summary in paragraph form if many concepts aren't covered. + +```asciidoc +[.summary] +== Lesson Summary + +In this lesson you learned how to install the Neo4j Python Driver, create a Driver instance, verify connectivity to your database, and execute your first Cypher statement. + +For async applications, link:https://neo4j.com/docs/python-manual/current/concurrency/[use the `AsyncGraphDatabase` method]. + +In the next lesson, you will take a quiz to test your knowledge of installing and creating a driver instance. + +``` + +For instructions on next lesson, check the next file in the directory ordered alphabetically. If that file exists, use the content of the file to write a short summary. If the file is empty or you cannot find a file in the filesystem, feel free to suggest a next lesson and add a `// TODO:` comment above. If the lesson is a challenge, use an assertive statement like "you will open a can of worms using the can of worms extraction methodology." diff --git a/.cursor/write-theory-lesson.mdc b/.cursor/write-theory-lesson.mdc new file mode 100644 index 000000000..74c87350f --- /dev/null +++ b/.cursor/write-theory-lesson.mdc @@ -0,0 +1,53 @@ +--- +description: +globs: +alwaysApply: false +--- +# Write a theory lesson + +Write a short theory lesson that introduces one or two key concepts to a beginner. The lesson should be factual, direct, and based on consistent examples from movie recommendations. It should be written in a tone that is casual, friendly, and succinct. Avoid filler language or motivational fluff. Stick to useful, clear information. Focus on where the content and subject will be useful for a developer or data scientist in their day to day lives. + +## Constraints + +- Keep the lesson under 5 minutes to read. +- Only introduce 1–2 new concepts per lesson. +- Use simple language, assume no prior knowledge. +- All examples must relate to movie recommendation systems. +- Use a consistent business-world analogy appropriate for developers or data scientists. +- Do not mix metaphors or use unrelated analogies. +- Do not include hands-on steps or exercises in this lesson. +- Break up content by level 2 and level 3 headings. +- You are describing something, not selling it. Stick to facts, avoid hyperoble. Only include information that is relevant. + +## Required Structure + +### 1. Introduction + +- One sentence recapping what has been learned previously where applicable. +- One short paragraph explaining why this concept is relevant in the context of the course or previous lesson, using a business scenario from movie recommendations. + +### 2. Prior Knowledge + +- If applicable, briefly mention what was covered in the previous lesson in one sentence. + +### 3. Concept(s) + +For each concept: + +- Provide a clear, plain-language definition. +- Use a consistent analogy from business, relevant to a developer or data scientist. +- Give a concrete example from movie recommendations. +- Include a sentence that someone might say aloud to explain the concept informally. +- (Optional) Include a short description of a supporting visual. + +### 4. Practical Context + +- One sentence applying how the concept or concepts fit into a larger system, product, or workflow. + +### 5. Teaser + +- One sentence describing what the learner will do or build in the next lesson, phrased as a challenge. + +## Instruction + +Write the final lesson content directly. Do not include bullet points, notes, or meta-commentary. This is the learner-facing copy. diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/course.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/course.adoc index 487bbf90f..81fbcf2e0 100644 --- a/asciidoc/courses/genai-mcp-build-custom-tools-python/course.adoc +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/course.adoc @@ -1,7 +1,45 @@ = Building GraphRAG Python MCP tools -:categories: llms:99 +:usecase: recommendations +:caption: Build your own GraphRAG MCP server with graph-backed tools and resources. +:categories: llms:30 +:duration: 2 hours +:repository: neo4j-graphacademy/genai-mcp-build-custom-tools-python -In this course, you will learn how to: +This course follows on from the link:/courses/genai-mcp-neo4j-tools/[Developing with Neo4j MCP Tools course], which introduces the Model Context Protocol and key concepts like Servers, Clients and Tools. + +In this course, you will build on that knowledge to create your own MCP server using the link:https://github.com/modelcontextprotocol/python-sdk[MCP Python SDK^] and create server features that can be consumed by any MCP client. + + + +== Prerequisites + +This course assumes that you have are familiar with the basics of Generative AI and Large Language Models. If you are not, we recommend that you take the link:/courses/genai-fundamentals/[GenAI Fundamentals] and link:/courses/genai-mcp-neo4j-tools/[Developing with Neo4j MCP Tools] courses first. + +We also assume a basic understanding of Python and command line tools. We assume that you have Python installed along with the `uv` package manager. +If you are not familiar with uv, you should also link:https://docs.astral.sh/uv/[review the uv documentation]. + +We also use the link:https://github.com/modelcontextprotocol/inspector[MCP Inspector^] to test and debug your MCP servers and tools. This tool is run through link:https://docs.npmjs.com/cli/v8/commands/npx[the `npx` command]^, so you will need Node.js to be installed. You can link:https://nodejs.org/en/download[download Node.js from the official website^]. + +The course features hands-on challenges using link:https://github.com/settings/copilot[GitHub CoPilot^], you will need to enable either the free or Pro version. + + +== Duration + +{duration} + +== What you will learn + +* How to build your own MCP servers with the MCP Python SDK. +* How to serve your tools, resources and prompts through your server. +* How to use the MCP Inspector to test and debug your tools and resources. +* How to use MCP tools to build MCP tools. + + +// TODO: Add number of lessons, challenges and quizzes +[.includes] +== This course includes + +* [lessons]#7 lessons# +* [challenges]#15 short hands-on challenges# +* [quizes]#20 simple quizzes to support your learning# -* Build your own MCP tools with the MCP TypeScript SDK. -* Serve your MCP tools with an MCP server. diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/1-mcp-python-sdk/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/1-mcp-python-sdk/lesson.adoc new file mode 100644 index 000000000..92f3799d3 --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/1-mcp-python-sdk/lesson.adoc @@ -0,0 +1,168 @@ += Building MCP servers +:type: lesson +:order: 1 + +In the link:/courses/genai-mcp-neo4j-tools/[Developing with Neo4j MCP Tools course], you learned the basics of the Model Context Protocol (MCP) and how to use the Neo4j Cypher MCP Server to enable AI agents to interact with Neo4j databases. + +In this course, you will learn how to build your own MCP servers with graph-backed tools and resources, creating a complete GraphRAG application. + +You will learn to build these tools with the MCP Python SDK, and you will use the MCP Inspector to test your servers. + + +== Understanding the MCP Python SDK + +The MCP Python SDK is a comprehensive library that implements the full Model Context Protocol specification for Python applications. +It provides both client and server implementations, making it easy to create MCP servers that expose custom functionality to AI agents. + + +The SDK includes two main approaches for building servers: + +* **FastMCP**: A high-level, decorator-based approach that makes it simple to create servers quickly +* **Low-level server**: A more flexible approach that gives you full control over the MCP protocol + +In this course, we will focus on the FastMCP approach. + +== Introducing FastMCP + +FastMCP is the high-level interface in the MCP Python SDK designed to make server development as simple as possible. +It uses Python decorators to automatically handle the protocol details, letting you focus on the business logic of your tools and resources. + +FastMCP is a high-level server implementation built on top of FastAPI, which takes a decorator approach to building an MCP server. +The `FastMCP` class provides decorators that can be used to register functions as MCP features, for example a tool or a resource. + +Let's take a look at a simple example of how we can protect against a commonly known weakness of LLMs, **counting**. +LLMs are probabilistic systems that struggle with deterministic tasks like counting occurrences of letters in words. + +We can solve this problem by using MCP to provide the LLM with access to a deterministic function that counts the occurrences of a letter in a word. + + +[source,python] +.server.py +---- +from mcp.server.fastmcp import FastMCP + +# Create an MCP server +mcp = FastMCP("Stawrbrerry") # <1> + +# Add a tool that counts letters (LLMs famously struggle with this!) +@mcp.tool() # <2> +def count_letters(text: str, search: str) -> int: + """ + Count occurrences of a letter in the text. + Use this tool when you need to find how many times a substring appears in a text. + """ + return text.lower().count(search.lower()) + +# Add a resource with a decorator +@mcp.resource("greeting://{name}") # <3> +def get_greeting(name: str) -> str: + """Get a personalized greeting""" + return f"Hello, {name}!" + +# Add a prompt +@mcp.prompt(title="Count Letters") +def count_letters_prompt(text: str, search: str) -> str: + return f"Count the occurrences of the letter '{search}' in the text:\n\n{text}" + +---- + +This code: + +1. The `FastMCP` class creates an instance of an MCP server called `Stawrbrerry`. +2. The `@mcp.tool()` decorator registers a function as an MCP tool that counts the occurrences of a letter in a word. +3. The `@mcp.resource()` decorator registers a function as an MCP resource that returns a personalized greeting. +4. The `@mcp.prompt()` decorator registers a function as an MCP prompt that provides the end-user with a pre-written prompt template to solve a common problem. + +== Using Decorators + +The code sample uses decorators to register functions as MCP features. +Let's take a closer look at the tool example: + +[source,python] +.server.py +---- +@mcp.tool() +def count_letters(text: str, search: str) -> int: + """ + Count occurrences of a letter in the text. + Use this tool when you need to find how many times a substring appears in a text. + """ + return text.lower().count(search.lower()) +---- + +The `@mcp.tool()` decorator tells the server that the `count_letters` function should be used as an MCP tool. +Reflection is then used to infer metadata about the tool. + +1. The tool has two inputs: `text` and `search`, both of which are typed as strings. +2. The output of the tool is an `int` +3. The string in the opening line is used to describe what the tool does and and when it should be used. + +The `@mcp.tool()` decorator accepts a number of optional arguments, which we will cover later in the course. + + +== Running the server + +To run the server, you can call the `run` method on your `FastMCP` instance. + +[source,python] +.server.py +---- +# ... + +if __name__ == "__main__": + mcp.run() +---- + +This method starts the MCP server using the `stdio` transport method by default and begins listening for incoming connections from MCP clients. + + +[TIP] +.Using the `fastmcp` command +==== + +You can also run the server from the command line using the `fastmcp` command. + +[source,bash] +---- +fastmcp run server.py +---- + +link:https://github.com/jlowin/fastmcp[Learn more about `fastmcp`]. +==== + + +=== Transport methods + +In the previous course, we also covered the different transport methods that can be used to connect to an MCP server; Standard Input/Output (`stdio`), and Streamable HTTP (`http`). +As we will develop a local MCP server in this course, we will focus on the `stdio` transport method. You can change the transport method by passing the `transport` parameter to the `run` method. + +[source,python] +---- +mcp.run( + transport="http", + host="127.0.0.1", + port=8000, + path="/mcp" +) +---- + +Streaming HTTP is recommended for web deployments. + +[TIP] +.The `fastmcp` command line tool +==== +You can also provide the `--transport`, `--host`, `--port`, and `--path` flags to the `fastmcp` command. +==== + + +[.summary] +== Summary + +In this lesson, you learned the foundational concepts for building MCP servers with Python: + +* **MCP Python SDK** - A comprehensive library that implements the full MCP specification, providing both client and server implementations +* **FastMCP** - A high-level, decorator-based approach that simplifies server development by automatically handling protocol details +* **Decorators** - Use `@mcp.tool()`, `@mcp.resource()`, and `@mcp.prompt()` to register functions as MCP features +* **Transport methods** - Run servers using `stdio` (default) for local development or `http` for web deployments + +In the next lesson, you will create your first MCP server using FastMCP and test it with the MCP Inspector. diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/2c-creating-a-server/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/2c-creating-a-server/lesson.adoc new file mode 100644 index 000000000..c4f0e0be0 --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/2c-creating-a-server/lesson.adoc @@ -0,0 +1,175 @@ += Creating your first MCP server +:type: challenge + +Now for a challenge! In the previous lesson, you learned about the MCP Python SDK and FastMCP. Now it's time to put that knowledge into practice by creating your own MCP server from scratch. + +Your challenge is to create a simple MCP server that demonstrates the core concepts you've learned, then run and test it using the tools covered in the previous lesson. + +include::../../../../../../shared/courses/codespace/get-started.adoc[] + +The setup instructions in the README will be open automatically when you open the Codespace. + +Your environment variables required for step 2 can be found further down this page. + +[NOTE] +.GitHub Codespace +==== +You can keep the Codespace open while completing the course. +You can open your existing codespaces at link:https://github.com/codespaces[github.com/codespaces^]. +==== + + +== Challenge Goals + +To complete this challenge, you will need to: + +1. Create a new MCP server using the MCP Python SDK. +2. Create a tool that counts the number of times a letter appears in a word. +3. Configure VS Code to use the MCP server with stdio. +4. Test the server using the Chat window in Agent mode. + +== Step-by-Step Instructions + +=== Step 1: Set up your project directory + +First, create a new directory for your MCP server project: + +[source,bash] +---- +mkdir server +cd server +---- + +=== Step 2: Initialize the project with uv + +Initialize a new Python project using `uv`: + +[source,bash] +---- +uv init +---- + +This will create a basic project structure with a `pyproject.toml` file and a `main.py` file that you will use to build your MCP server. + +=== Step 3: Add the MCP dependency + +Add the MCP Python SDK to your project: + +[source,bash] +---- +uv add "mcp[cli]" +---- + +=== Step 4: Create your MCP server + + +Open `main.py` in your editor and add the following code to create a simple MCP server: + +[source,python] +.main.py +---- +from mcp.server.fastmcp import FastMCP + +# Create an MCP server +mcp = FastMCP("Strawberry") + +@mcp.tool() +def count_letters(text: str, search: str) -> int: + """Count occurrences of a letter in the text""" + return text.lower().count(search.lower()) + +# Run the server when executed directly +if __name__ == "__main__": + mcp.run() +---- + +=== Step 5: Configure your server in VS Code and test with Agent mode + +Now let's configure your server to work with VS Code's Agent mode. This will allow you to interact with your MCP server through a conversational interface. + +First, let's run the server to make sure it works: + +[source,bash] +---- +uv run main.py +---- + +Because the server is running with `stdio`, there will be no output in the terminal but the absense of errors is a good sign. +Use the `Cmd+C` / `Ctrl+C` key combination to cancel the server. + + + +Now, let's configure the server in VS Code. Open up `.vscode/mcp.json` and add the following: + +[source,json] +---- +{ + "servers": { + "Strawbrerry": { + "type": "stdio", + "command": "uv", + "args": [ + "--directory", + "server", + "run", + "main.py" + ] + } + } +} +---- + + +[TIP] +.Using the `--directory` flag +==== +The `--directory` flag is used to specify the directory where the server is located. +Without this, the `uv` command may not use the dependencies installed in the project. +==== + +=== Step 6: Verify your implementation + + +To test your server, open up the Chat window in **Agent** mode: + +1. Open the Command Palette (`Cmd+Shift+P` or `Ctrl+Shift+P`) +2. Execute the "Chat: Open Chat (Agent)" command + +Now try asking the following question: + +[copy]#How many times does the letter 'r' appear in the word 'strawberry'?# + +The agent should discover the `count_letters` tool and prompt you to confirm the tool call. +It should respond with the answer `3`. + + +[TIP] +.Experiment further +==== +Try modifying your server by: + +* Adding more counting tools (words, characters, etc.) +* Testing different types of text with your letter counting tool +* Making the tool case-sensitive or case-insensitive +* Adding error handling for edge cases +==== + +== That's it! + +You have just created your first MCP server! + +The Chat window in VS Code is a useful way to test your server, but it doesn't give you the full picture of what the MCP server is capable of. +In the next lesson, you will learn about the MCP Inspector, which is a tool that allows you to inspect the MCP server and its tools. + + +[.summary] +== Summary + +In this challenge, you successfully built your first MCP server from scratch: + +* **FastMCP setup** - Created a new MCP server using the FastMCP class with the MCP Python SDK +* **Tool implementation** - Added a `count_letters` tool using the `@mcp.tool()` decorator to solve LLM counting limitations. +* **Server installation** - Configured the server for VS Code using `uv run mcp install main.py` +* **Agent mode testing** - Tested the server functionality through VS Code Agent mode with conversational queries + +In the next lesson, you will learn about context management for handling server lifecycle and resource management. \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/mcp-inspector.png b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/mcp-inspector.png new file mode 100644 index 000000000..4217cf14d Binary files /dev/null and b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/mcp-inspector.png differ diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/tool-form.png b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/tool-form.png new file mode 100644 index 000000000..4ffb27ab9 Binary files /dev/null and b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/tool-form.png differ diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/tools.png b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/tools.png new file mode 100644 index 000000000..cb9c02e5e Binary files /dev/null and b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/images/tools.png differ diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/lesson.adoc new file mode 100644 index 000000000..c79a45306 --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/3-mcp-inspector/lesson.adoc @@ -0,0 +1,149 @@ += The MCP Inspector +:type: lesson +:order: 3 + +// * What is the MCP Inspector? +// * Using MCP Inspector in Codespaces +// * Testing tools and resources with the Inspector + +Great! You now have your first MCP server running. But testing it in the Chat window in VS Code isn't the most efficient or cost-effective way to test your server. + +In this lesson, you will learn about the MCP Inspector, a tool that allows you to test and debug your MCP servers and tools through a UI. + +== Introducing the MCP Inspector + +The MCP Inspector is a tool that allows you to test and debug your MCP servers and tools through a UI. + +// TODO: screenshot with strawberry tool +image::images/mcp-inspector.png[The MCP Inspector UI] + +The left hand panel allows you to define the connection details for the MCP server you want to test. + +Once connected to a server, the server features are listed to the right. + + +=== Running the MCP Inspector + +The tool is written in JavaScript, so you will need Node.js installed and the `npx` command to run it. + +// TODO: Npm installation instructions + +[source,shell] +.Running the MCP Inspector +---- +npx @modelcontextprotocol/inspector +---- + +[TIP] +.Using `npx` +==== +The `npx` command is a package runner for Node.js. It is used to run Node.js packages without installing them globally. + +You can install npx along with Node.js by link:https://nodejs.org/en/download[downloading Node.js from the official website^]. +==== + +==== Pre-filling the Server details + +You can pre-fill the details of your server by appending the configuration details to the command. + +[source,shell] +.Running the MCP Inspector with pre-filled server details +---- +npx @modelcontextprotocol/inspector uv --directory $PWD/server run main.py +---- + +This will run the `main.py` file in the `server` directory using the `uv` command as we instructed VS Code to do in the previous lesson. + +[TIP] +.`$PWD` +==== +The `$PWD` environment variable is used to get the current working directory, which is required by the `uv` command. + +The command assumes that you are running the command from the root of the project. +If you are running the command from the `server/` directory you can omit the directory name from the command. +==== + + +Once you have opened the UI and verified the Transport Type is `stdio`, you can click the **Connect** button to connect to your server. + + + +== Using the MCP Inspector + +// To connect to your server, you will need to either specify the full path of your file, or switch the transport method to HTTP. + +// [source,shell] +// ---- +// npx @modelcontextprotocol/inspector +// Starting MCP inspector... +// ⚙️ Proxy server listening on 127.0.0.1:6277 +// 🔑 Session token: 32be7bf018a86d10c0428db91e0ff4ad32236a664e176642451b1ebbcaf69869 +// Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth + +// 🔗 Open inspector with token pre-filled: +// http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=32be7bf018a86d10c0428db91e0ff4ad32236a664e176642451b1ebbcaf69869 + +// 🔍 MCP Inspector is up and running at http://127.0.0.1:6274 🚀 +// ---- + +Clicking the link in the console will open the MCP Inspector in your browser with the server details pre-filled on the left hand side. Click the **Connect** button to connect to your server. + +Once you have connected, take a look at the **History** tab. You should see a list item called `1. initialize`, which represents the handshake between the client and server. + +You should see a request sent with the mode `initialize` and in response, a list of capabilities and server information. + +[source,json] +.initialize response +---- +{ + "capabilities": { + "experimental": {}, + "prompts": { + "listChanged": false + }, + "resources": { + "subscribe": false, + "listChanged": false + }, + "tools": { + "listChanged": false + } + }, + "serverInfo": { + "name": "Strawberry", + "version": "1.10.1" + } +} +---- + + +== Testing server features + +At the top of the right hand panel, you should see a set of tabs that correspond to the features of the server. + +image::images/tools.png[Inspector Tabs] + +If you click on the **Tools** tab, you should see the `count_letters` tool that you created in the previous lesson. +Selecting the tool will open a form to the right hand side with a form generated based on the parameters requested for the tool. + +image::images/tool-form.png[There is no 'i' in team] + +You can fill in the form and click the **Run tool** button to invoke the tool. + +== Next steps + +As you progress through the course, you will use the MCP Inspector to test and debug your MCP server. + + +Now it is time to try it for yourself! + + + +[.summary] +== Summary + +In this lesson, you learned about the MCP Inspector, an essential tool for anyone building or debugging MCP servers and tools. + +You can link:https://github.com/modelcontextprotocol/inspector[find documentation for the MCP Inspector on GitHub^]. + +In the next challenge, you will run the MCP Inspector in a GitHub Codespace and test the `count_letters` tool for yourself. diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/5c-testing-server/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/5c-testing-server/lesson.adoc new file mode 100644 index 000000000..e400c7b0a --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/lessons/5c-testing-server/lesson.adoc @@ -0,0 +1,47 @@ += Inspecting your server +:type: challenge + +In the previous lesson, you learned how to use the MCP Inspector to connect to your MCP server, explore its features, and test tools through a user-friendly UI. You saw how to launch the Inspector, connect to your MCP server via stdio, and run tools using the auto-generated form. + +In this challenge, you will run your MCP server in GitHub Codespaces, launch the MCP Inspector, and use it to test your tool implementation. + +To pass the challenge, you will need to: + +1. Start your MCP server and the Inspector in a Codespaces environment. +2. Connect the Inspector to your running server. +3. Use the Inspector UI to run a tool and verify its output. + +== Step 1: Start the Inspector and Server Together + +Open a terminal in your Codespaces environment and run the following command from the project root: + +[source,shell] +---- +npx @modelcontextprotocol/inspector uv --directory $PWD/server run main.py +---- + +This will launch both the MCP Inspector and your server. Wait for the Inspector to start and note the local URL (e.g., http://127.0.0.1:6274). + + +== Step 2: Connect the Inspector to Your Server + +Click on the URL to open up the server. +Codespaces will perform port forwarding to allow you to access the server from your browser. + +In the left panel, ensure the Transport Type is set to `stdio` and the server command is pre-filled. Click **Connect**. + + +== Step 3: Run a Tool in the Inspector + +Once connected, go to the **Tools** tab. Select your tool (e.g., `count_letters`), fill in the required parameters, and click **Run tool**. + +Does it work? + +read::It works![] + +[.summary] +== Summary + +In this challenge, you started your MCP server using the MCP Inspector in Codespaces, connected to your server, and ran a tool through the Inspector UI. You now have a repeatable workflow for testing and debugging your MCP tools interactively. + +In the next module, you will start to build our your MCP server with tools, resources and prompts. diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/module.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/module.adoc similarity index 58% rename from asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/module.adoc rename to asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/module.adoc index 198106502..a743b565b 100644 --- a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/module.adoc +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/1-building-servers/module.adoc @@ -1,8 +1,11 @@ = Building MCP Tools with FastMCP -:order: 3 +:order: 1 + +Now you have a server running, it is time to start building your own tools. In this module, you will learn: * How to build your own MCP tools and resources using the MCP Python SDK * How to create an MCP server using FastMCP -* How to use your tools with an MCP client. +* How to use your tools with MCP Inspector. + diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/1-features-recap/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/1-features-recap/lesson.adoc new file mode 100644 index 000000000..82dc57848 --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/1-features-recap/lesson.adoc @@ -0,0 +1,5 @@ += Server Features + +* Tools +* Resources +* Prompts \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/2-building-tools/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/2-building-tools/lesson.adoc new file mode 100644 index 000000000..fc5f0b1ce --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/2-building-tools/lesson.adoc @@ -0,0 +1,6 @@ += Building your own GraphRAG tools +:order: 2 + +* What is a tool? (recap) +* Using the @tool decorator +* Structured outputs for tools \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/3-build-a-tool/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/3-build-a-tool/lesson.adoc new file mode 100644 index 000000000..7792a75cb --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/3-build-a-tool/lesson.adoc @@ -0,0 +1,8 @@ += Build a tool +:type: challenge +:order: 3 + +* Create a tool that returns a list of movies in a genre +* Implement structured output for the tool results +* Test the tool with the MCP Inspector + diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/4-resources/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/4-resources/lesson.adoc new file mode 100644 index 000000000..b17eb303f --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/4-resources/lesson.adoc @@ -0,0 +1,6 @@ += Using Resources +:order: 4 + +* What is a resource? (recap) +* Creating resources with FastMCP +* Dynamic resource templates \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/5c-create-resource/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/5c-create-resource/lesson.adoc new file mode 100644 index 000000000..2656aaa1f --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/5c-create-resource/lesson.adoc @@ -0,0 +1,6 @@ += Create a Movie resoure +:order: 5 +:type: challenge + +* Create a resource for the `Movie` label to get movie by tmdbId +* test it in mcp inspector \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/6-prompts/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/6-prompts/lesson.adoc new file mode 100644 index 000000000..7fd47c3bf --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/lessons/6-prompts/lesson.adoc @@ -0,0 +1,6 @@ += Building Prompts +:order: 6 + +* What is a prompt? (recap) +* Creating prompts with FastMCP +* Prompt templates \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/module.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/module.adoc new file mode 100644 index 000000000..07d9cde33 --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/2-building-server-features/module.adoc @@ -0,0 +1,9 @@ += Building Server Features +:order: 2 + +In this module, you will learn: + +* How to turn functions into tools using the `@tool` decorator. +* How to serve resources from the MCP server. +* How to provide pre-defined prompts to an MCP client. + diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/10c-integrated-workflow/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/1-integrated-workflow/lesson.adoc similarity index 96% rename from asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/10c-integrated-workflow/lesson.adoc rename to asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/1-integrated-workflow/lesson.adoc index 14f57d4a5..ee75fe6a2 100644 --- a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/10c-integrated-workflow/lesson.adoc +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/1-integrated-workflow/lesson.adoc @@ -1,6 +1,6 @@ = Developing with MCP tools :type: challenge -:order: 10 +:order: 1 * Writing a cursor rule to use the MCP server to validate the query * Iterative prompt that: diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/4c-text-to-cypher-tool/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/2c-text-to-cypher-tool/lesson.adoc similarity index 100% rename from asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/4c-text-to-cypher-tool/lesson.adoc rename to asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/2c-text-to-cypher-tool/lesson.adoc diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/3-summary/lesson.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/3-summary/lesson.adoc new file mode 100644 index 000000000..f452eee6c --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/lessons/3-summary/lesson.adoc @@ -0,0 +1,10 @@ += Next Steps +:type: lesson +:order: 2 + +* Course recap: Building MCP servers with Python +* Best practices for MCP server development +* Next steps and additional resources + + + diff --git a/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/module.adoc b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/module.adoc new file mode 100644 index 000000000..e54c7428c --- /dev/null +++ b/asciidoc/courses/genai-mcp-build-custom-tools-python/modules/3-integrated-workflows/module.adoc @@ -0,0 +1,6 @@ += Integrating tools into workflows +:order: 3 +In this module, you will learn: + +* How to integrate tools into your workflows. +* How to use MCP tools to create novel MCP tools in your server. diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/1-mcp-python-sdk/lesson.adoc b/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/1-mcp-python-sdk/lesson.adoc deleted file mode 100644 index b78adf97b..000000000 --- a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/1-mcp-python-sdk/lesson.adoc +++ /dev/null @@ -1,7 +0,0 @@ -= Building your own MCP tools - -* MCP SDKs -* How the library works -* Building a tool -* Resources -* Content types diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/2-introduction-to-fast-mcp/lesson.adoc b/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/2-introduction-to-fast-mcp/lesson.adoc deleted file mode 100644 index 40037b009..000000000 --- a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/2-introduction-to-fast-mcp/lesson.adoc +++ /dev/null @@ -1,5 +0,0 @@ -= Introduction to FastMCP - -* What is FastMCP? -* How to start a server -* How to change transport methods \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/3-building-tools/lesson.adoc b/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/3-building-tools/lesson.adoc deleted file mode 100644 index 17243e4e1..000000000 --- a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/3-building-tools/lesson.adoc +++ /dev/null @@ -1 +0,0 @@ -= Building your own GraphRAG tools \ No newline at end of file diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/5c-graph-resource/lesson.adoc b/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/5c-graph-resource/lesson.adoc deleted file mode 100644 index 8d46d214d..000000000 --- a/asciidoc/courses/genai-mcp-neo4j-tools/_move/3-building-mcp-tools-fastmcp/lessons/5c-graph-resource/lesson.adoc +++ /dev/null @@ -1,4 +0,0 @@ -= Creating a Graph Resource -:type: challenge - -* Create a resource that gets a node by its ID. diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/course.adoc b/asciidoc/courses/genai-mcp-neo4j-tools/course.adoc index 8ba2242e1..29e09d750 100644 --- a/asciidoc/courses/genai-mcp-neo4j-tools/course.adoc +++ b/asciidoc/courses/genai-mcp-neo4j-tools/course.adoc @@ -11,12 +11,6 @@ Model Context Protocol, referred to as MCP, is an open standard designed to conn It enables AI agents to access and interact with external resources as part of their reasoning step, allowing them to perform more complex tasks and collaborate effectively. -In this course, you will learn: - -* How MCP Servers define sets of tools that AI agents can discover and use. -* How MCP Clients establish connections to access and call tools to perform tasks. -* How Neo4j's suite of MCP tools can help aid your development on top of Neo4j. -* How to build your own link:/knowledge-graph-rag/[GraphRAG^] tool to retrieve information from a Neo4j database. == Prerequisites @@ -32,9 +26,10 @@ The course features hands-on challenges using link:https://github.com/settings/c == What you will learn -* How the MCP protocol works -* How to integrate Neo4j's MCP tools into your IDEs and AI applications -* How to build GraphRAG applications with Neo4j MCP tools +* How MCP Servers define sets of tools that AI agents can discover and use. +* How MCP Clients establish connections to access and call tools to perform tasks. +* How Neo4j's suite of MCP tools can help aid your development on top of Neo4j. +* How to create your own link:/knowledge-graph-rag/[GraphRAG^] workflow to retrieve information from a Neo4j database. [.includes] diff --git a/asciidoc/courses/genai-mcp-neo4j-tools/llms.txt b/asciidoc/courses/genai-mcp-neo4j-tools/llms.txt index de8855409..5a66d68ff 100644 --- a/asciidoc/courses/genai-mcp-neo4j-tools/llms.txt +++ b/asciidoc/courses/genai-mcp-neo4j-tools/llms.txt @@ -11,12 +11,32 @@ Learn how to use the Model Context Protocol to create intelligent AI application * **MCP Client** - Manages one-to-one connections to servers and executes tools on behalf of the host * **MCP Host** - An application (like Claude Desktop, VS Code, or custom agents) that manages clients and determines which tools to use * **MCP Tools** - Discrete functions with unique identifiers, descriptions, and parameters that can be invoked by AI agents -* **ReAct Framework** - A continuous loop of planning, reasoning, and acting that agents use to achieve specific goals * **Agent** - A system that acts independently using tool calling to access information and take actions to achieve specific goals * **Neo4j Cypher MCP Server** - A specialized MCP server that provides AI agents with the ability to read and write data to Neo4j databases * **Schema Discovery** - The process of understanding database structure before generating queries to prevent AI hallucinations * **stdio Transport** - Communication method where client starts server locally and communicates through standard input/output streams +### ReAct Framework + +A continuous loop of planning, reasoning, and acting that agents use to achieve specific goals: + +1. **Planning** - Analyze the task and break it down into smaller, manageable sub-tasks +2. **Reasoning** - Select the most appropriate tools and actions for each sub-task based on available capabilities +3. **Acting** - Execute the selected tools and gather results from the actions taken +4. **Evaluation** - Check if the goal has been achieved or if further iterations are needed +5. **Feedback** - Use results to refine the approach and inform the next iteration of the loop + +### MCP Server Features + +MCP servers provide three main types of capabilities: + +* **Tools** - Discrete functions that can be invoked by AI agents to perform specific actions (e.g., database queries, API calls, file operations) +* **Resources** - Static or dynamic content that can be read by clients (e.g., files, documents, configuration data) +* **Prompts** - Pre-defined prompt templates that can be used to guide AI interactions and provide consistent context + +[Reference: What is MCP?](https://graphacademy.neo4j.com/courses/genai-mcp-neo4j-tools/1-what-is-mcp/1-getting-started) + + ## Installation and Configuration ### VS Code MCP Configuration @@ -48,13 +68,15 @@ Learn how to use the Model Context Protocol to create intelligent AI application ### get-neo4j-schema Tool -```text -// Tool invocation examples: -// "Describe the data model" -// "What node labels and relationship types are available in the database?" -// "How are User and Movie nodes related?" +**Purpose**: Discovers the database schema including node labels, properties, and relationships. -// Example schema output: +**Input**: Natural language requests about the database structure: +- "Describe the data model" +- "What node labels and relationship types are available in the database?" +- "How are User and Movie nodes related?" + +**Output**: +```json [ { "label": "Movie", @@ -87,40 +109,54 @@ Learn how to use the Model Context Protocol to create intelligent AI application ### read-neo4j-cypher Tool -```text -// Safe read-only queries that don't modify data -// Example invocations: -// "What are the top 10 movies by revenue?" -// "Who directed the movie 'The Matrix'?" - -// Example query for top movies by revenue: -MATCH (m:Movie) -WHERE m.revenue IS NOT NULL -RETURN m.title AS title, m.revenue AS revenue -ORDER BY m.revenue DESC -LIMIT 10 - -// Example query for finding directors: -MATCH (d:Director)-[:DIRECTED]->(m:Movie {title: 'The Matrix'}) -RETURN d.name AS director +**Purpose**: Executes safe read-only Cypher queries that don't modify data. + +**Input**: Natural language requests for data retrieval: +- "What are the top 10 movies by revenue?" +- "Who directed the movie 'The Matrix'?" +- "Show me all users who rated movies with 5 stars" + +**Output**: +```json +[ + { + "title": "Avatar", + "revenue": 2847246203 + }, + { + "title": "Avengers: Endgame", + "revenue": 2797501328 + }, + { + "title": "Titanic", + "revenue": 2257844554 + } +] ``` ### write-neo4j-cypher Tool -```text -// Write operations that modify data (requires approval) -// Example invocations: -// "Create a new user named Sarah" -// "Add a 5-star rating from John to The Godfather" +**Purpose**: Executes write operations that modify database data (requires user approval). -// Example create user query: -CREATE (u:User {name: 'Sarah', userId: 'sarah123'}) -RETURN u +**Input**: Natural language requests for data modification: +- "Create a new user named Sarah" +- "Add a 5-star rating from John to The Godfather" +- "Update the movie budget for Titanic to 200000000" -// Example create rating query: -MATCH (u:User {name: 'John'}), (m:Movie {title: 'The Godfather'}) -CREATE (u)-[:RATED {rating: 5}]->(m) -RETURN u, m +**Output**: +```json +[ + { + "u": { + "identity": 1234, + "labels": ["User"], + "properties": { + "name": "Sarah", + "userId": "sarah123" + } + } + } +] ``` [Reference: Using the Neo4j Cypher MCP Server](https://graphacademy.neo4j.com/courses/genai-mcp-neo4j-tools/2-using-neo4j-mcp-tools/1-mcp-neo4j-cypher) @@ -144,7 +180,7 @@ RETURN u, m ### Transport Methods -#### stdio - +#### stdio Standard input/output - for local server communication @@ -159,8 +195,7 @@ Example stdio configuration: #### HTTP -Remote server via Server-Sent Events (SSE) or Streaming HTTP - +Remote server via Server-Sent Events (SSE) or Streaming HTTP. ### Example tool definition structure @@ -174,34 +209,3 @@ Remote server via Server-Sent Events (SSE) or Streaming HTTP } # No parameters required } ``` - -### ReAct Agent Framework - -```python -# ReAct loop implementation concept: -def react_agent_loop(user_input, available_tools): - """ - Continuous loop of planning, reasoning, and acting - """ - goal_achieved = False - - while not goal_achieved: - # PLANNING: Analyze task and break into sub-tasks - plan = analyze_task(user_input) - - # REASONING: Select appropriate tools for each sub-task - selected_tools = select_tools(plan, available_tools) - - # ACTING: Execute tools and gather results - results = execute_tools(selected_tools) - - # EVALUATION: Check if goal is achieved - goal_achieved = evaluate_progress(results, user_input) - - # FEEDBACK: Use results to refine next iteration - user_input = incorporate_feedback(results, user_input) - - return results -``` - -[Reference: What is MCP?](https://graphacademy.neo4j.com/courses/genai-mcp-neo4j-tools/1-what-is-mcp/1-getting-started)