> For the complete documentation index, see [llms.txt](https://nexafin.gitbook.io/api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nexafin.gitbook.io/api/mcp/authentication.md).

# Authentication

## OAuth 2.1 via WorkOS

Nexafin MCP implements the [OAuth 2.0 Protected Resource Metadata](https://datatracker.ietf.org/doc/html/rfc9728) standard (RFC 9728). MCP clients like Claude Desktop and ChatGPT discover the authorization server automatically via the discovery endpoint.

### Discovery endpoint

```
GET https://app.nexafin.com/.well-known/oauth-protected-resource
```

**Response:**

```json
{
  "resource": "https://app.nexafin.com",
  "authorization_servers": ["https://your-workos-issuer.authkit.app"],
  "scopes_supported": ["openid", "profile", "email", "offline_access"],
  "bearer_methods_supported": ["header"],
  "resource_documentation": "https://nexafin.com/docs/api"
}
```

### How it works

1. Your MCP client reads the discovery endpoint to find the authorization server (WorkOS)
2. You are redirected to WorkOS to log in with your Nexafin account
3. WorkOS issues an OAuth token to the MCP client
4. The client sends requests with `Authorization: Bearer <token>`

{% hint style="info" %}
Most MCP clients handle this flow automatically. You just need to provide the MCP endpoint URL and the client takes care of the rest.
{% endhint %}

## Public vs authenticated methods

Some MCP protocol methods do not require authentication:

| Method                      | Auth required | Description               |
| --------------------------- | :-----------: | ------------------------- |
| `initialize`                |       No      | Protocol handshake        |
| `notifications/initialized` |       No      | Client ready notification |
| `ping`                      |       No      | Connection health check   |
| `tools/list`                |       No      | List available tools      |
| `tools/call`                |    **Yes**    | Execute a tool            |

## Error responses

| Status | Meaning                                                                                                                                                                                                                                                  |
| ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `401`  | Missing or invalid token. Response includes a `WWW-Authenticate` header pointing to the OAuth discovery endpoint: `Bearer resource_metadata="https://app.nexafin.com/.well-known/oauth-protected-resource", scope="openid profile email offline_access"` |
| `403`  | Token is valid but your Nexafin account isn't linked or set up yet. The error message includes a link to complete setup.                                                                                                                                 |


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://nexafin.gitbook.io/api/mcp/authentication.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
