> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/mcp-integration-contributor-guide/python-implementation.md).

# Python implementation

Your MCP integration's main function should do the following:

* Create an MCPApiModule Client instance with the vendor’s MCP server URL and authentication details.
* Route commands to the appropriate handler.
* Use MCPApiModule for all MCP operations.
* Handle errors using `extract_root_error_message()` and `return_error()`.
* Always close the client connection in a finally block.

#### Key principles <a href="#uuid-b647b6c1-20ed-69f1-cb8c-2d2e41ba00e1_bridgehead-id235585281118072" id="uuid-b647b6c1-20ed-69f1-cb8c-2d2e41ba00e1_bridgehead-id235585281118072"></a>

* Use hard-coded vendor-specific values (server URL, auth type, command prefix, server name) as constants.
* Extract only user-configurable parameters from `demisto.params()`, including tokens, credentials, and custom headers.
* Use BaseException in error handling to catch async exception groups.
* Mark the main function with `# pragma: no cover`.

For a simple token-based example, see `Packs/GitHubMCP/Integrations/GitHubMCP/GitHubMCP.py` . For a multi-auth example, see `Packs/GenericMCP/Integrations/GenericMCP/GenericMCP.py`&#x20;

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/mcp-integration-contributor-guide/python-implementation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
