main.py•3.13 kB
# generated by fastapi-codegen:
# filename: openapi.yaml
# timestamp: 2025-06-29T07:44:30+00:00
import argparse
import json
import os
from typing import *
from autogen.mcp.mcp_proxy import MCPProxy
from autogen.mcp.mcp_proxy.security import APIKeyQuery, BaseSecurity
from fastapi import Path
from models import Section, TimePeriod
from models.Mostemailed_section__time_period_ import (
JsonGetResponse,
JsonGetResponseModel,
JsonGetResponseModel1,
)
from models.Mostshared_section__time_period_ import (
JsonGetResponse,
JsonGetResponseModel,
)
from models.Mostviewed_section__time_period_ import JsonGetResponse
app = MCPProxy(
description='Get lists of NYT Articles based on shares, emails, and views.',
termsOfService='http://developer.nytimes.com/tou',
title='Most Popular API',
version='2.0.0',
servers=[
{'url': 'http://api.nytimes.com/svc/mostpopular/v2'},
{'url': 'https://api.nytimes.com/svc/mostpopular/v2'},
],
)
@app.get(
'/mostemailed/{section}/{time-period}.json',
tags=['content_engagement_metrics'],
security=[
APIKeyQuery(name="api-key"),
],
)
def g_e_t_mostemailed_section_time_period_json(
section: Section, time_period: TimePeriod = Path(..., alias='time-period')
):
"""
Most Emailed by Section & Time Period
"""
raise RuntimeError("Should be patched by MCPProxy and never executed")
@app.get(
'/mostshared/{section}/{time-period}.json',
tags=['content_engagement_metrics'],
security=[
APIKeyQuery(name="api-key"),
],
)
def g_e_t_mostshared_section_time_period_json(
section: Section, time_period: TimePeriod = Path(..., alias='time-period')
):
"""
Most Shared by Section & Time Period
"""
raise RuntimeError("Should be patched by MCPProxy and never executed")
@app.get(
'/mostviewed/{section}/{time-period}.json',
tags=['content_engagement_metrics'],
security=[
APIKeyQuery(name="api-key"),
],
)
def g_e_t_mostviewed_section_time_period_json(
section: Section, time_period: TimePeriod = Path(..., alias='time-period')
):
"""
Most Viewed by Section & Time Period
"""
raise RuntimeError("Should be patched by MCPProxy and never executed")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="MCP Server")
parser.add_argument(
"transport",
choices=["stdio", "sse", "streamable-http"],
help="Transport mode (stdio, sse or streamable-http)",
)
args = parser.parse_args()
if "CONFIG_PATH" in os.environ:
config_path = os.environ["CONFIG_PATH"]
app.load_configuration(config_path)
if "CONFIG" in os.environ:
config = os.environ["CONFIG"]
app.load_configuration_from_string(config)
if "SECURITY" in os.environ:
security_params = BaseSecurity.parse_security_parameters_from_env(
os.environ,
)
app.set_security_params(security_params)
mcp_settings = json.loads(os.environ.get("MCP_SETTINGS", "{}"))
app.get_mcp(**mcp_settings).run(transport=args.transport)