Skip to main content

MCP Servers & AI Agents SDK

SDK for integrating Model Context Protocol (MCP) servers and AI agents with AuthSec authentication and authorization.

How to Integrate Authentication into Your MCP Server / SDK Agent?

Learn how to integrate your AI agent by securely authenticating your MCP server or agent using our authentication API.

Step 1: Install AuthSec SDK

pip install git+https://github.com/authsec-ai/sdk-authsec.git

Step 2: Create Your Secure MCP Server (server.py)

from authsec_sdk import protected_by_AuthSec, run_mcp_server_with_oauth

# Tool 1: Accessible to all authenticated users
@protected_by_AuthSec("hello")
async def hello(arguments: dict) -> list:
return [{
"type": "text",
"text": f"Hello, {arguments['_user_info']['email']}!"
}]

# Start the server
if __name__ == "__main__":
run_mcp_server_with_oauth(
client_id="your-client-id-here",
app_name="My Secure MCP Server"
)

Step 3: Run Your Server

python server.py

How Do You Do Autonomous Agent (Machine to Machine) Authorization?

Learn how to deploy SPIRE agents on Kubernetes, Docker, and VM environments for secure machine-to-machine communication.

Step 1: Add Helm Repository

# Add AuthSec Helm repo
helm repo add authsec https://charts.authsec.ai
helm repo update

Step 2: Create values.yaml

cat > icp-agent-values.yaml <<EOF
# ICP Agent Configuration
image:
repository: your-docker-registry.example.com/icp-agent
tag: latest
pullPolicy: Always

# Agent settings
agent:
tenantId: "your-tenant-id-here"
clusterName: "my-k8s-cluster"
icpServiceUrl: "https://your-icp-server.example.com/spiresvc"
logLevel: info
socketPath: /run/spire/sockets/agent.sock

# Service Account
serviceAccount:
create: true
name: icp-agent

# Security Context
securityContext:
runAsUser: 0
runAsGroup: 0
runAsNonRoot: false
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
add:
- SYS_PTRACE # Required for process attestation
seccompProfile:
type: RuntimeDefault

# Resources
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "100m"
memory: "128Mi"

# Health probes
healthProbe:
enabled: true
port: 8080
livenessProbe:
initialDelaySeconds: 30
periodSeconds: 60
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
initialDelaySeconds: 10
periodSeconds: 30
timeoutSeconds: 5
failureThreshold: 3

# Tolerations (run on all nodes)
tolerations:
- operator: Exists

# Node selector (optional - restrict to specific nodes)
nodeSelector: {}
# role: worker

# Affinity (optional)
affinity: {}
EOF

Step 3: Install Agent

# Install in default namespace
helm install icp-agent authsec/icp-agent \
-f icp-agent-values.yaml \
--namespace default \
--create-namespace

# Wait for DaemonSet to be ready
kubectl rollout status daemonset/icp-agent -n default

Step 4: Verify Installation

# Check DaemonSet
kubectl get daemonset -n default

# Check pods (should be 1 per node)
kubectl get pods -n default -l app=icp-agent -o wide

# Check logs
kubectl logs -n default -l app=icp-agent --tail=50

# Check health
kubectl exec -n default -l app=icp-agent -- curl http://localhost:8080/healthz