DEV Community

diwushennian4955
diwushennian4955

Posted on

mcp-brasil is Trending — Here's How to Add AI Image Generation to Brazilian APIs

mcp-brasil is Trending — Here's How to Add AI Image Generation to Brazilian APIs

mcp-brasil just exploded on GitHub with 373+ stars in days. It exposes 28 Brazilian public APIs — IBGE, Banco Central, TSE, DataJud, INPE, BrasilAPI, and more — directly to AI assistants via the Model Context Protocol (MCP).

Brazilian developers are using it to ask Claude and GPT questions like:

  • "Quais os 10 maiores contratos do governo federal em 2024?"
  • "Qual a tendência da taxa Selic nos últimos 12 meses?"

But there's a gap: mcp-brasil reads data, but can't generate content. What if you could also generate images, speak Portuguese via TTS, or create videos from that data?

That's what this tutorial covers.

What Is MCP?

MCP (Model Context Protocol) is Anthropic's open protocol for connecting AI assistants to external tools. mcp-brasil implements it for 28 Brazilian government APIs with 213 tools, smart BM25 discovery, and batch execution.

pip install mcp-brasil
Enter fullscreen mode Exit fullscreen mode

The Missing Piece: NexaAPI

NexaAPI is a unified AI inference API — 50+ models, OpenAI-compatible, at $0.003/image (5x cheaper than alternatives).

Available on RapidAPI: rapidapi.com/user/nexaquency

Python Tutorial: IBGE Data + AI Image Generation

# pip install nexaapi requests
from nexaapi import NexaAPI
import requests

client = NexaAPI(api_key='YOUR_RAPIDAPI_KEY')

# Fetch city data from IBGE (mcp-brasil pattern)
def get_city_info(city_code):
    url = f'https://servicodados.ibge.gov.br/api/v1/localidades/municipios/{city_code}'
    return requests.get(url).json()

# Generate AI image — $0.003/image!
def generate_city_image(city_name):
    result = client.image.generate(
        model='flux-schnell',
        prompt=f'Beautiful aerial view of {city_name}, Brazil, photorealistic, vibrant colors',
        width=1024,
        height=1024
    )
    return result.image_url

# Generate Portuguese TTS
def generate_portuguese_tts(text):
    result = client.audio.tts(
        text=text,
        voice='pt-BR-female',
        model='tts-multilingual'
    )
    return result.audio_url

# Combined workflow
city = get_city_info(3550308)  # São Paulo
image_url = generate_city_image(city['nome'])
print(f"✅ City image: {image_url}")  # Cost: $0.003

tts_url = generate_portuguese_tts(f"Bem-vindo a {city['nome']}!")
print(f"✅ Portuguese TTS: {tts_url}")
Enter fullscreen mode Exit fullscreen mode

JavaScript Tutorial: CNPJ Lookup + Company Image

// npm install nexaapi axios
import NexaAPI from 'nexaapi';
import axios from 'axios';

const client = new NexaAPI({ apiKey: 'YOUR_RAPIDAPI_KEY' });

async function getCNPJInfo(cnpj) {
  const { data } = await axios.get(`https://brasilapi.com.br/api/cnpj/v1/${cnpj}`);
  return data;
}

async function generateCompanyImage(companyName) {
  const result = await client.image.generate({
    model: 'flux-schnell',
    prompt: `Professional headquarters of ${companyName} in Brazil, modern architecture`,
    width: 1024,
    height: 768
  });
  return result.imageUrl;  // Only $0.003!
}

// Run it
const company = await getCNPJInfo('33000167000101');
const imageUrl = await generateCompanyImage(company.razao_social);
console.log(`Generated: ${imageUrl}`);
Enter fullscreen mode Exit fullscreen mode

Pricing Comparison

Provider Image TTS
NexaAPI $0.003 $0.015/1K chars
OpenAI DALL-E 3 $0.04 $0.015/1K
Stability AI $0.02 N/A
ElevenLabs N/A $0.30/1K

NexaAPI is 10x cheaper for images.

Use Cases

  • 🏙️ City Tourism: IBGE data → photorealistic city images
  • 🏢 Company Intelligence: CNPJ lookup → company visualization
  • 🗳️ Electoral Analysis: TSE data → infographics + Portuguese TTS
  • 🌿 Environmental: INPE fire data → visual reports

Resources


Have you used mcp-brasil in your projects? What Brazilian APIs are you most excited about? Drop a comment below! 🇧🇷

mcpbrasil #BrazilAI #DesenvolvimentoBR #AIBrasil

Top comments (0)